-
-
Notifications
You must be signed in to change notification settings - Fork 34
How do I access the response headers? #168
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
Comments
The mutations generated by this library do not return headers. Instead of using the generated mutation hook, create your own hook. import { addPet } from "../openapi/requests/services.gen";
import {
AddPetMutationResult,
UseFindPetsKeyFn,
} from "../openapi/queries";
import { AxiosError } from "axios";
import { AddPetData, AddPetError } from "../openapi/requests/types.gen";
// create your own hook
const { mutate, isError } = useMutation<
AddPetMutationResult,
AxiosError<AddPetError>,
AddPetData
>({
mutationKey: [useAddPetKey],
mutationFn: (options) => addPet(options),
});
// mutation
mutate(
{
body: { name: text },
},
{
onSuccess: (data) => {
const contentDisposition = data.headers["content-disposition"];
// do something
},
}
); |
@7nohe are there any plans to expose the response headers on the queries and mutartions at some point? |
What is the reason for hiding the headers from the result of the queries and mutations? Headers can carry important information, like x-total-count for pagination. |
You can get headers in the generated response by describing the headers as part of the response on the API spec. https://swagger.io/specification/ see Response Object and the Header Object. |
@seriouslag |
@7nohe Having the same issue. Need access to headers response. @seriouslag do you have any working example to share? thanks |
I have a mutation which returns a Content-Disposition header with the filename, etc. But my generated mutation returns only a string, any way to get access to the response headers? Thanks for the great package!
The text was updated successfully, but these errors were encountered: