Reputation: 13
I have a ProjectStep resource in my application and I have to create an API endpoint that will be used to update my ProjectStep to mark it as finished and create the next ProjectStep. In my REST API I could just do something like this :
PATCH /project-mark/1
POST /project-mark
But I would like to use only one request to update the current step, create a new one and return the newly created ProjectStep.
What method would you use? A PATCH request updating an existing resource and returning a different resource doesn't sound like a good idea.
Thank's
Upvotes: 0
Views: 458
Reputation: 381
Use a PUT request, please see this link
https://stackoverflow.com/questions/630453/put-vs-post-in-rest
Use PUT APIs primarily to update existing resource (if the resource does not exist then API may decide to create a new resource or not). If a new resource has been created by the PUT API, the origin server MUST inform the user agent via the HTTP response code 201 (Created) response and if an existing resource is modified, either the 200 (OK) or 204 (No Content) response codes SHOULD be sent to indicate successful completion of the request.
If the request passes through a cache and the Request-URI identifies one or more currently cached entities, those entries SHOULD be treated as stale. Responses to this method are not cacheable.
Upvotes: 1