-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to get response headers in case of no content #71
Comments
Hello, There is a "hacky" way indeed. Instead of using the generated method |
Right now there's no "proper" support for retrieving headers from response, regardless of having body defined. Unless you call "sendRequest" manually and work with the PSR response object. (as suggested by @JasonBenett) The name of the classes returned by the *ApiClient class are pretty tied to 200/201 (*ResponseBody). 204 meaning no content also means no body 😄 but still you'd need something to be returned so you could Ideally I guess we would need to introduce an extra layer (if we really want to be able to ->getHeaders() calling the operationName methods from *ApiClient). So that you'd call e.g. we could also tweak the existent *ResponseBody adding the headers there, although it feels weird to work with a concrete *ResponseBody object for a 204 response which has no body... so maybe we could rename the class, but also we could have issues with mixing something like "getHeaders()" which would return HTTP response headers with a "getHeaders()" from a response that has {"headers": ...} in the payload So either using sendRequest manually as a workaround or we'd need to introduce an extra layer (even though this breaks backward compatibility, it's I guess safer and more consistent - you get Response and inside you have body and headers). |
Thank you guys, I’ll go with sendRequest for now. I could also imagine a getLastResponse method, which would return always the response of the last executed API call. It could be useful in a few test scenarios as well but also would require introducing a state into the client. |
When generating a client where response body is empty I'm not able to get the response object to check headers when needed.
Example
Is there any other way to get response object after executing request in api clients?
The text was updated successfully, but these errors were encountered: