alexanoid alexanoid - 3 months ago 42
reST (reStructuredText) Question

REST service resource naming

I'm designing a new REST API endpoints and have a doubts about API urls.

For example I have a

entity and corresponding

In order to GET a specific product, everything is clear - I have to use something similar to:

GET /products/{productId}

in order to create a new one everything is clear too:

POST /products with a product details in the HTTP request body

but how to deal with product update ?

There is two options which I can see right now:

PUT /products/{productId} with a new product details in the HTTP request body


PUT /products with a {productId} and new product details in the HTTP request body

the same question for product delete.

What is the best practice here in order to send
to server ?


You should use PUT /products/{id} to update the product. In the Body you should send the ressource or the changes.

The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server.

Reference HTTP-Methods