Search code examples
restpost-redirect-get

What status code should be used if somebody sends a GET request to a POST endpoint?


I have a URL:

/item/delete/

It accepts a POST request. When it gets the POST request, it deletes the item indicated in the POST payload, and does the PRG dance.

What do I do if it receives a GET request? I'd like for it to return some kind of status code -- probably something in the 400 range? -- but I'm not sure which to use, or if I'm thinking about this the wrong way.

Would love some RESTful advice.


Solution

  • You should use: 405 Method Not Allowed

    See section 10.4.6 of https://www.ietf.org/rfc/rfc2616