Reputation: 25892
I'm designing a new REST API endpoints and have a doubts about API urls.
For example I have a Product
entity and corresponding /products
API.
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
or
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 {productId}
to server ?
Upvotes: 0
Views: 45
Reputation: 357
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
Upvotes: 1