Bekacru / better-fetch

Advanced fetch wrapper for typescript
https://better-fetch.vercel.app/
210 stars 7 forks source link

top level `query` in `createFetch()` doesn't merge with `schema` #16

Open OwenVey opened 4 weeks ago

OwenVey commented 4 weeks ago

In my case, the OMDb API required an apikey query param passed in every request so I set up my createFetch like so:

export const omdbApi = createFetch({
  baseURL: 'http://www.omdbapi.com',
  query: {
    apikey: 'xxxxxxxx',
  },
  schema: createSchema(
    {
      '/': {
        query: z.object({
          i: z.string(),
        }),
      },
    },
  ),
});

However, when calling the API like so

omdbApi('/', { query: { i: 'tt22022452'} })

only the i query param gets sent.

sinanusluer commented 2 weeks ago

I think you can use the onRequest hook.

Docs: https://better-fetch.vercel.app/docs/hooks#on-request 🤟