0

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

jerry
  • 59
  • 1
  • 7
  • This is more grammar than actual coding. Unless you're following a really strict guidelines you're more than welcome to use either. To put it more bluntly, use @jreikes left an interesting comment on [this](https://stackoverflow.com/questions/31089221/what-is-the-difference-between-put-post-and-patch) question: The terminology used in this answer would only be understandable by someone who does not need to ask the underlying question. – Andrei Nov 15 '18 at 10:44
  • thanks a lot for your anwsers ;) – dumartinetj Nov 15 '18 at 10:57
  • Can you please rate my answer? – Alesandro Giordano Nov 15 '18 at 10:59
  • @AlesandroGiordano I did but I don't have enough rep just yet so my vote isn't displayed. Have a nice day – dumartinetj Nov 15 '18 at 12:14

1 Answers1

1

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.

  • As promoted by SO guidelines, when you find a new question that has been already answered on SO, you should flag that question as duplicate instead to re-use the same answer to make reputation points with the effort produced by other users ;-) – gp_sflover Nov 15 '18 at 13:07
  • I don't know how to do that – Alesandro Giordano Nov 15 '18 at 13:16
  • Under the question's tags there is a "flag" text-link (_near "edit" and "share"_). It will open a popup from which you can choose the right flagging reason. – gp_sflover Nov 15 '18 at 13:31
  • But this is a question about which call I have to make to do something, the "duplicate" is about the difference between calls... the user must know a PUT request before – Alesandro Giordano Nov 15 '18 at 13:33
  • The OP asked which method is better to use for a determined action because he simply doesn't know all the available methods, so the answer in the duplicate is correct because it gave to the OP the knowledge to understand by himself which method to use for this case (_and all the future ones_). For example, on SO there are tons of daily questions that cause a php sintax error, so the right answer for 99% of these questions is an explanation (_that already exist from years on SO_) to start to understand from where they could coming from and how to debug them. – gp_sflover Nov 15 '18 at 13:47
  • Anyway when you don't have really a "duplicate", at least you should avoid only-link answer, leaving the link as reference and adding a clear and exhaustive explanation that cover exactly the issue/s described in the question. – gp_sflover Nov 15 '18 at 13:52
  • Than you @gp_sflover, here is a description – Alesandro Giordano Nov 15 '18 at 13:54
  • As always I read in rush and I realized that maybe there are other answers to use as a better reference for the duplicate (for example as [What is difference between HTTP methods GET, POST, PUT and DELETE](https://stackoverflow.com/questions/18395523/what-is-difference-between-http-methods-get-post-put-and-delete)) but no matter regarding the points already explained (_not my downvote_). – gp_sflover Nov 15 '18 at 14:07