question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Document response body negotiation for PUT and POST requests via Accept header

See original GitHub issue

When doing some integration testing, I discovered the hard way that unless configured otherwise, PUT & POST only return a response body when the HTTP Accept header is set (due to #418). My regular calls apparently set the headers but it took me some time, digging through code, and some web searching to figure out why my integration test was not seeing a response body.

Looking into the reference guide, I see almost no mention of this behavior. The only reference is in 4.1.2. Default Status Codes, where it refers to the status code (but not the response body):

If the configuration values (RepositoryRestConfiguration.returnBodyOnUpdate and RepositoryRestConfiguration.returnBodyCreate) are explicitly set to null, the presence of the HTTP Accept header is used to determine the response code.

I think it would be beneficial if the response body behavior were more explicitly documented. In particular, it would be helpful if the reference guide called out that the presence of a response body is dependent on the accept header unless configured otherwise.

Incidentally, I think this Stack Overflow user likewise ended up getting bitten by this exact same piece of behavior, so I don’t think it’s just me who’s had to track down this mostly undocumented behavior.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
odrotbohmcommented, Sep 29, 2021

I’ve pushed a fix in 6d19e96. If you have further ideas, what could be clarified, feel free to comment.

1reaction
mjustincommented, Sep 27, 2021

Can you elaborate on which other parts of the documentation you have looked for in hope of finding information?

For this particular search, I was mostly looking through this reference guide. I was observing the behavior, and wanted to see if it was actually documented somewhere.

I am a bit puzzled because you quote a section from the reference documentation that describes the behavior and in the immediate next sentence ask for that behavior to be mentioned in the docs. Which you have just quoted. In the paragraph before.

If you’ll note, the quoted paragraph states nothing about the response body, just about the response status code. One could probably guess that it’s likely that such a request conditionally returns a body or not based on the presence of the HTTP header (since why else would it be using different response codes), though as far as I can tell, it’s not outright stated in the documentation.

So in other words, while the documentation section tells the reader what happens to the status code of a response based on whether the Accept header is present, it makes no mention of what happens to the body of the response.

As a side note, on reread of the whole section, it looks like only PUT/PATCH/DELETE behavior is called out (in the 204 No Content default status code section). It’s not stated how POST behaves.

That said, I assume it’s rather a matter of discoverability.

That’s a pretty big part of it, yeah. It’s not straightforward to discover this, especially if you’re thinking in terms of response bodies and not response status codes. Also, having a quotable section of the documentation makes it easier to answer other peoples’ issues related to this, since the quoted section can be referenced directly.

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTTP Content Negotiation in REST APIs
Generally, if no Accept header is present in the request, the server can send pre-configured default representation type.
Read more >
Content negotiation - HTTP - MDN Web Docs
In HTTP, content negotiation is the mechanism that is used for serving different representations of a resource to the same URI to help...
Read more >
HTTP/1.1: Header Field Definitions
The Accept request-header field can be used to specify certain media types which are acceptable for the response. Accept headers can be used...
Read more >
Implementing content negotiation based on HTTP headers - IBM
You can use content negotiation based on HTTP Accept headers to determine the content format that is used to exchange data between servers ......
Read more >
RFC 7231: Hypertext Transfer Protocol (HTTP/1.1)
This document defines the semantics of HTTP/1.1 messages, as expressed by request methods, request header fields, response status codes, and response header ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found