URL pattern in Restful service

Asked

Viewed 672 times

1

I am developing a service that will provide some functions for external access, using REST architecture. It’s the start of a Restapi for the company. But let’s get to the problem. I need to update some point data for a particular product. So I decided to use as default for the URL:

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

In the above case, the field value refers to the new product value. However, I would not like to make this transaction using the GET method. So I thought I’d adopt this pattern for URL:

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

I would like to use the POST method and pass the new product data through a JSON. In the research I’ve done I haven’t found anything like it, so I’m also not sure if it’s the right way to do it.

  • For partial changes it is more interesting to use the method PATCH.

1 answer

2


Depends, the POST would be the most suitable method for insertion and not for updating.

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

The basic methods resemble a CRUD:

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

In this case, what you would have to use to be the "most correct" way 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 have to enter a new one, then the POST would be the most suitable, but this goes from your data architecture.

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

These links can help you:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.