T
T
tigra2020-03-01 15:59:58
Java
tigra, 2020-03-01 15:59:58

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,
  }
  ]
}

Actually, how can I do it right, if with item I have more than a dozen related resources that need to be requested with a list?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question