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

Add url to middleware Options type #1376

Open
snarky-puppy opened this issue Dec 3, 2024 · 2 comments
Open

Add url to middleware Options type #1376

snarky-puppy opened this issue Dec 3, 2024 · 2 comments
Labels
feature 🚀 New feature or request needs info ⏳ Further information is required

Comments

@snarky-puppy
Copy link

snarky-puppy commented Dec 3, 2024

Description

url starts out in Options but later gets Omitted here

export type Options<
  T extends { url: string } = { url: string },
  ThrowOnError extends boolean = boolean,
> = T extends { body?: any }
  ? T extends { headers?: any }
    ? OmitKeys<OptionsBase<ThrowOnError>, 'body' | 'headers'> & Omit<T, 'url'>
...

I can't really figure out why, does anyone know?

It would be useful for me to build a rate limiting middleware using the pre-processed url. The rate limiter is per endpoint so I can't use the processed url (i.e. I need /users/{userId} and not /users/123)

Currently using this code to extract the url anyway...

import {Options} from '@hey-api/client-fetch';

const myMiddleware = (request: Request, config: Options) => {
  const url = (config as {url: string}).url;
  ...
@snarky-puppy snarky-puppy added the feature 🚀 New feature or request label Dec 3, 2024
@mrlubos
Copy link
Member

mrlubos commented Dec 3, 2024

Hey @snarky-puppy, the main use case for Options is to type the SDK functions where you don't want to pass the URL every time. I'll need to clean this up for your use case. To clarify, the URL is actually passed as needed, it's just types that need to be improved?

@mrlubos mrlubos added the needs info ⏳ Further information is required label Dec 3, 2024
@snarky-puppy
Copy link
Author

Hey @mrlubos, ok that makes sense, I guess maybe a different Options type for middleware is needed?

FWIW I'm using the fetch-client and I can see the generated url isn't passed in via options, only the url from the SDK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 🚀 New feature or request needs info ⏳ Further information is required
Projects
None yet
Development

No branches or pull requests

2 participants