0

I am considering two approaches when updating rest api and i am not sure how to choose which approach to follow

For example

GET /service/1000

{
"service_id": 1000,
"name": "Some service"
"status": "ACTIVE"
}

Now If I want to update this service I could do

PUT /service/1000
{
"service_id": 1000,
"name": "Some service"
"status": "INACTIVE"
}

or

POST /service/1000/update-status
{
"status": "INACTIVE"
}

or even

POST /service/1000/activate
{

}

and

POST /service/1000/deactivate
{

}

So my question is what is the rule of thumb to follow when choosing approach how to update REST?

EDIT This question is not about when to use POST/PATCH/PUT, it is about should resource be update calling the same resource, or should it be updated using an action. For example, twitter uses actions https://developer.twitter.com/en/docs/api-reference-index

mko
  • 4,825
  • 8
  • 45
  • 97
  • Possible duplicate of [REST API - PUT vs PATCH with real life examples](https://stackoverflow.com/questions/28459418/rest-api-put-vs-patch-with-real-life-examples) – Andrei Dragotoniu Mar 14 '19 at 08:43
  • The idea behind REST is to have URIs that match resources, not actions, so the `/update-status`, `/activate` and `/deactivate` should not be used. – ChatterOne Mar 14 '19 at 09:12
  • Twitter for example uses actions https://developer.twitter.com/en/docs/api-reference-index – mko Mar 14 '19 at 09:44

1 Answers1

0

From what you are considering put is more appropriate however I in some cases patch is more appropriate so when you are changing the value of resources you consider using patch but when you are adding a new property put is more appropriate see--- REST API PATCH or PUT

Monday A Victor
  • 349
  • 3
  • 13