What should a RESTful API POST/DELETE return in the body?

dB. picture dB. · Oct 31, 2011 · Viewed 18.3k times · Source

To follow and unfollow a person via a RESTful API, I have

  • POST /person/bob/follow
  • DELETE /person/bob/follow

What should these return in the body?

  1. A collection of everyone you follow
  2. The person you just followed / unfollowed
  3. A status like { status: "ok" }
  4. Nothing.

Answer

Sjoerd picture Sjoerd · Oct 31, 2011

If you respond on errors using a HTTP server status, the status code does not say anything. If you respond with a 404 Not Found if there is no user Bob, or a 500 Internal Server Error if the database is broken, the only successful response you will ever get is OK. Users do not have to check the status code, they only have to check the HTTP status code.

I suggest you return nothing, and the fact that it is a successful response (i.e. 200 OK or 204 No Content) indicates that the operation was successful.