httprestposthttpwebrequestput

Are PUT and POST requests required/expected to have a request body?


I'm writting a RESTful api, and at I'm thinking about the process of a user creating a key. I have the following possibilities:

I looked at this API from joyent and in all their PUT and POST requests they pass some data in the request body. Is this expected ? Is it really wrong not to require a request body in a PUT and POST request ?


Solution

  • I asked this question on the Http-WG. This was the most precise answer I got:

    It's important to note that a message without a body can still carry a representation, because a representation is the combination of the body (which can be zero-length) and headers.

    See:
    http://tools.ietf.org/html/draft-ietf-httpbis-p3-payload-11#section-4

    https://lists.w3.org/Archives/Public/ietf-http-wg/2010JulSep/0276.html

    In summary, POST does not require a body. I would expect the same justification can be applied to PUT.