URL pattern in RESTful service

1

I'm developing a service that will provide some functions for external access, using REST architecture. It is the beginning of a RestAPI for the company. But let's get into the problem. I need to update some punctual data for a particular product. So I decided to default to the URL:

http://..../Produtos/{id}/ValorVenda/{valor}

In the above case, the value field refers to the new value of the product. However, I would not like to do this transaction using the GET method. So I thought about adopting this URL pattern:

http://..../Produtos/{id}

I would like to use the POST method and pass the new product data through a JSON. I did not find anything similar in the search I made, so I'm not sure if that's the right way to do it.

    
asked by anonymous 19.04.2016 / 15:05

1 answer

2

Depends, POST would be the most appropriate method for insertion and not for update.

The idea of a REST service is to use the methods for each situation according to what they offer.

The basic methods look like a CRUD:

  • GET: READ
  • POST: CREATE
  • PUT: UPDATE
  • DELETE: DELETE

In this case, what you would have to use to be the "correct" would be the PUT and not the POST if you were to update an existing value, but if you do not have the value and you have to insert a new value, then POST would be the most appropriate, but that goes from your data architecture.

In this way you could send information through Body of this method to a URL of type http://www.suaurl.com.br/Produtos/{id} and capture the request from the other side.

These links may help you:

19.04.2016 / 15:26