I'm trying to design a RESTful API where the users can fetch a single product or list of products in a single GET request. Each product has a unique id.
The single product URL is simple enough:
http://mycompany.com/api/v1/product/id
This returns the information for a single product. I'm confused as to how the URL for multiple product information should look like.
How about
http://mycompany.com/api/v1/product/ids
where ids is a comma separated list of ids?
Using multiple threads: The REST API can use multiple threads to handle multiple client requests. This means that each request will be processed on a separate thread, and the REST API can process multiple requests at the same time. Using a queue: The REST API can use a queue to store incoming requests from clients.
You can't stop the user from resubmitting a new request with the same ticket, but you can reject it on the server side, with a "Duplicate request" error. Right, but people do that on purpose - submit a form, press back because they know they need to correct something, submit form again.
You could make them 2 representations of the same resource and with content negotiation.. 100% restful.
In this case, we refer to these resources as singleton resources. Collections are themselves resources as well. Collections can exist globally, at the top level of an API, but can also be contained inside a single resource. In the latter case, we refer to these collections as sub-collections.
I would recommend thinking of it like you are listing multiple representations of the resource filtered by id. As such you make a GET
request to the base resource:
https://example.com/api/v1/products
And filter the response list by id
:
https://example.com/api/v1/products?id=1,2,3
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