Skip to content
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

How do I access the response headers? #168

Open
atresnjo opened this issue Nov 4, 2024 · 1 comment
Open

How do I access the response headers? #168

atresnjo opened this issue Nov 4, 2024 · 1 comment

Comments

@atresnjo
Copy link

atresnjo commented Nov 4, 2024

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!

@7nohe
Copy link
Owner

7nohe commented Jan 20, 2025

@atresnjo

The mutations generated by this library do not return headers. Instead of using the generated mutation hook, create your own hook.
The following is an example using the axios client. (The problem is that the types generated by the Hey API do not have headers, though.)

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
      },
    }
  );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants