0

When implementing a RESTful API, we should deliver the user proper responses on actions.

The architecture of REST API basing on proper building of the link and sending it with proper verb allows user to ask the API any request about any data. What response code should I provide to the user, when he will ask for method that is not implemented for the data he is asking for?

Example:

API is allowing the user to add articles via postAction but not allowing to delete articles at all. What response should I provide to the user when he will send REST DELETE request to my API? 404?

3 Answers 3

2

If it's a user permission issue, 403 seems most appropriate. (Forbidden - you're not allowed to do this but someone else might be able to)

If no-one is allowed to perform a DELETE but it's an otherwise valid URI, 405. (Method not allowed)

If it's an access to a non-existent resource, but DELETEs are supported against such resources, then 404 is appropriate. (Not found)

If it's more than one of these scenarios (i.e. the user isn't allowed to DELETE, and the URI they've provided is for a resource that doesn't actually exist) then you need to decide which piece of information is more important. I'd probably pick 404.

Sign up to request clarification or add additional context in comments.

Comments

0

You need to respond with response code 405 Method Not Allowed.

List of status codes: Wikipedia

Comments

0

There are basically four methods that are used in RESTfull services. GET, POST, PUT and DELETE.

You are probably adding article using POST service.

When a REST api called using different method other than the expecting one then API automatically returns HTTP status code 405 (Method not allowed)

If you are allowing this API to using DELETE method as well and then any one can call using DELETE method as well. If you want to disallow user to delete the particular then you may return 403 (forbidden) response code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.