2

I'm getting a '405 Method Not Allowed' when I attempt for a DELETE without passing the resource Id which needs to be deleted.Here is my URL

http://localhost:8080/api/vendors/delete/1234/

where ideally I should have given the ID at the end of the URL like:

http://localhost:8080/api/vendors/delete/1234/{id}

I'm convinced it should be a 405 but my QA team thinks otherwise. They say it should be a 400. Can someone point out to me any resource which clearly specifies what HTTP code it should be for this scenario.

Akash Yellappa
  • 2,126
  • 28
  • 21
  • 1
    If you have that endpoint with a different method then 405 is correct. If you don't have that endpoint with a different method then it should be 404. – takendarkk May 28 '19 at 18:54

2 Answers2

1
  1. For your main question, if the method is DELETE and the path /api/vendors/delete/1234/ is valid for other methods but not for DELETE, then 405 Method Not Allowed ("A request method is not supported for the requested resource") is correct, since there is a "resource" at that path that doesn't support delete, e.g. it might support GET to retrieve a list of vendors.

    If there is no resource there, i.e. the method doesn't matter, then 404 Not Found ("The requested resource could not be found") would be the correct response.

  2. If the method is DELETE, not GET, PUT, POST, or any of the others, you shouldn't need .../delete/... in the path.

  3. If you're trying to delete Vendor 1234, then path should be http://localhost:8080/api/vendor/1234 and the method should be DELETE. The action handler should use /api/vendor/{id} in the declaration.

Andreas
  • 154,647
  • 11
  • 152
  • 247
  • Ah, the answer I was looking for. Actually your third point saved the day. Once I got rid of 'delete' in the URL I see a 404 for a request without an {id} in the URL. Which is expected.. Thank you so much Andreas – Akash Yellappa May 28 '19 at 19:23
0

As per my opinion 404 Not Found or 400 Bad Request is a good option. Please refer to this answer as well HTTP Status Codes

Shashank Gupta
  • 321
  • 3
  • 15