0

I'm fairly new to using REST to retrieve data from a database. I'm hoping to make a website which has an SQLite database on it. It seems Backbone.js will be a good fit for what I'm trying to do, and it says they interact well with a RESTful API to get data from a database. I read Understand Backbone.js REST calls to get a better understanding of how REST works.

I found this simple API https://github.com/alixaxel/ArrestDB to get data from an SQLite database.

What I am still not getting is how (if possible) to JOIN two tables.

For example, I have a Books table with BookID, Title and AuthorID, and an Authors table with AuthorID, First Name, Last Name, Age. AuthorID in the Books table is a foreign key to the Authors table.

If I use ArrestDB and go to http://api.mysite.com/books/ I'll get a JSON response of the books, and http://api.mysite.com/authors/ I'll get a JSON response from the Authors. How do I get all the books with the full information of their respective authors? This would be accomplished in SQL using a JOIN. Do I have to merge them manually in Javascript?

T J
  • 42,762
  • 13
  • 83
  • 138
robev
  • 1,909
  • 3
  • 23
  • 32
  • Find a more robust REST library that is also better documented and more current – charlietfl Jun 25 '17 at 23:14
  • Any suggestions? I really just need a wrapper around my sqlite db – robev Jun 25 '17 at 23:16
  • Lots of different php frameworks around that you could use. Take a look at http://cacodaemon.de/index.php?id=48 for example – charlietfl Jun 25 '17 at 23:21
  • I see what you're saying. That's a lot more customizable. What would the GET request look like for a JOIN? A URL to a non-existent database? For example http://api.mysite.com/fullbooks/ which would to the JOIN on both Books and Authors and return the JSON response – robev Jun 25 '17 at 23:47
  • Name the route anything you want and do the join inside it. URL and database tables don't have to use same name conventions...it's up to you whatever you use and whatever data processing you do inside that route – charlietfl Jun 26 '17 at 00:40
  • Maybe consider turning your comments into answer – robev Jun 26 '17 at 12:05
  • Typically, in REST, a join of related resources is left up to the client. As a client, I would send a request to get the books collection. Then I would send requests, in parallel, to retrieve the author representation for each book. – Joshua Jones Jun 26 '17 at 15:24

0 Answers0