vim
vim

Reputation: 135

RESTful API: is it appropriate to make POST request without data

I'm working on service that collects prices from third-party online shop. I use RESTful API to add new product id and get price by id.

To add new product: POST /product/12345 (parses product page and stores price to db)

To update stored price: PUT /product/12345 (parses product page and updates price in db)

To get price: GET /product/12345 (return price from db if data exists)

My question is am I doing it right way (especially with POST verb)?

Upvotes: 1

Views: 164

Answers (2)

Sanjith
Sanjith

Reputation: 85

Normally the API calls for the Post : Data will not be placed on the url, which can be mentioned like below

To add new product: POST /product/new

Thanks, SVN

Upvotes: 4

user1907906
user1907906

Reputation:

To add a new product, POST to the collection resource /product:

POST /product/

The server will assign an ID to the new Product and return it.

201 Created
Location: http://example.com/product/9876

Edit:

If you already know the ID, create the product using PUT:

PUT /product/9876

Upvotes: 2

Related Questions