Answer the question
In order to leave comments, you need to log in
How to build a URL in the REST ideology?
I am developing a REST API.
The point is simple.
1. There are suppliers (many)
2. There is a calculation of the price for the service for each supplier (the supplier has one service). The cost depends on the size of the object that will be passed as a parameter.
Option number 1 :
/providers/ - display information about all providers (ID, name, description, etc.)
/providers/provider_id - display information about only one specific supplier
/providers/provider_id/price?size=123 - display cost services of a specific supplier (for example, the cost of painting an object of size 123 by provider_id)
Everything would be fine, but I want to make a request to display the prices of ALL suppliers at once for painting an object of size 123. It turns out that we need to add more:
/prices/?size=123 - the output will be prices from all service providers
Option number 2 :
/providers/ - display information about all suppliers (ID, name, description, etc.)
/providers/provider_id - display information only one specific supplier
/prices/provider_id?size=123 - - display the cost of the service of a specific supplier (for example, the cost of painting an object with a size of 123)
/prices/?size=123 - the output will be prices from all service providers
In fact, the only difference here is the options in one URL.
Actually a question: what approach is more correct?
Or maybe I'm fundamentally wrong in building routing from the point of view of the REST API ideology?
Answer the question
In order to leave comments, you need to log in
Maybe it will help:
* pyvideo.ru/video/87/python-rest-api
* thenextcode.ru/post/10-kak-pravilno-delat-rest-api...
* habrahabr.ru/post/38730
As far as I understand it wins an API that contains:
* version
* nouns
* tends not to contain verbs
GOOD:
super-duper-api/ver1/resource
BAD:
super-duper-api/getResources
I like the first option better.
But there is a slippery moment in it:
/providers/provider_id/price?size=123
It turns out that this is a special case of /providers/provider_id, and there is no new "prices" resource as such, it's just an attribute of the provider, so I suggest using /providers/provider_id with filters both by fields and by values
example: /providers/provider_id?fields=id,prices&data=123
In general, I advise you to read
Oreilly.REST.API.Design.Rulebook
Option 1 is completely correct.
I will add that a selection by price and a specific supplier can also be done like this
/prices/?size=123&provider_id=1
jsonapi.org to help.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question