Imagine a resource such as Authors. An Author has multiple books, multiple pictures, etc.
In some pages of my app, I only need the surface author data such as name. In other pages, I need all the nested resources as well. How do I handle the loading of nested resources?
Do I load everything in one call such that:
GET /authors returns {
name: x,
books: {
bookname: a,
...
}
}
Accept an optional parameter that specifies the nested objects, such as:
GET /authors?include=books&pictures
Any insight appreciated
I would go with the following REST-style URLs:
GET /authors - to get list of all authors
GET /authors/{authorId} - basic info about the concrete author in one request
GET /authors/{authorId}/detailed - detailed info about the concrete author in one request
Additionally, you could have the following methods to extract specific info about author:
GET /authors/{authorId}/images - get all images by author
GET /authors/{authorId}/images/{imageId} - get one image by author
GET /authors/{authorId}/books - get all books by author
GET /authors/{authorId}/books/{bookId} - get one book by author
Also I recommend to read REST resource naming conventions here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With