willscripted
willscripted

Reputation: 1456

Can you request `204 No Content`?

Is there a codified way to indicate to an HTTP server that the client would prefer not to receive content? A special Accept header or the like? Eg, Accept: no-content

When present, the server would return a 204 No Content response. When not present, the server would default to the application/json representation.

The use case is for a particularly large PUT request. Getting the content back is useful for development and debugging, but costly for production systems. I realize this could be hacked together with custom headers or params; I'm looking for a cleaner solution.

Edit: I am writing the service

Upvotes: 1

Views: 314

Answers (2)

Evert
Evert

Reputation: 99523

If you don't control the server, you can't really. The best option you have is to kill the tcp connection as soon as you get the response.

If you are also developing the server though, you do have the option. The best design is to not send the result by default, and allow users to explicitly request the new presentation with this:

Prefer: return=representation

This header is defined in rfc7240.

Upvotes: 3

bmargulies
bmargulies

Reputation: 100013

There is no general set of semantics for PUT that causes it to return the content. It's entirely up to the particular service. The HTTP specification says nothing about the content coming back at you. Either the particular service you are throwing PUTs at has some means of controlling its verbosity, or it does not. Since you have not specified it, no one can be more helpful than this.

Upvotes: 2

Related Questions