A
A
Alexiuscrow2015-03-31 23:21:34
RESTful API
Alexiuscrow, 2015-03-31 23:21:34

Is it against the principles of RESTful services to receive mixed data?

Task
There is a server and there is a client. The client needs to receive from the server a list of supermarkets and promotions that are currently held in these supermarkets.
Solutions
Solution #1

  1. Get a list of supermarkets
    GET http://myservice.com/markets
  2. Get a list of all promotions for each of the supermarkets
    GET http://myservice.com/discounts

In order to complete the task , 2 requests to the server are required.
Solution #2
  1. Get a list of supermarkets and promotions
    GET http://myservice.com/markets_and_discounts

In order to complete the task, only 1 request to the server is required.
Question
Does solution #2 violate the principles of RESTful services?
Thank you.
PS It is necessary that the server comply with the principles of REST, but I would also like it not to be overloaded with the number of calls.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Lemeshev, 2015-04-09
@vanlmshv

It is possible to connect supermarkets with stocks on the backend side through a connection like "has many" or "many to many", depending on what logic you have there.
Make a request for GET http://myservice.com/markets with some parameter.
For example, http://myservice.com/markets?expand=discountand accordingly, if there is expandalso its value discount, make a selection of all supermarkets and corresponding stocks for each supermarket and return all the data at once.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question