Answer the question
In order to leave comments, you need to log in
What is the correct way to request related resources for a list in a REST API?
I have a resource "Product"
POST item
GET item
GET item/{id}
PUT item/{id}
DELETE item/{id}
When getting a list of items, I want to get another related entity as item-favorite for each item. How is it done correctly?
My options are:
- GET item/{id}/favorite where there will be a request for each entity, which will be expensive, but it seems like REST
- GET item/favorites a separate method where the item-favorites array will be returned to me
- GET item? extend=favorites what some extend parameter where the api user himself will be able to request connections as needed, for example
{
'id' => 1,
'name' => 'Название',
'favorite' => [
{
id => 555,
item_id => 1,
}
]
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question