hey-api / openapi-ts

✨ Turn your OpenAPI specification into a beautiful TypeScript client
https://heyapi.vercel.app
Other
1.08k stars 89 forks source link

Non-global clients/configs #587

Closed mothershipper closed 4 months ago

mothershipper commented 4 months ago

Description

Hi there! Wondering if there are plans to support config/client instances (rather than globals/singletons), or if you'd be open to a pull request that adds that?

Our use case is that for certain APIs we have a dynamic number of client credentials and would feel better about constructing and caching or disposing of the config and clients between uses. I believe we can use interceptors as a workaround currently, but generally we try to avoid global state where we can.

mrlubos commented 4 months ago

Hey @mothershipper, yes, that sounds like a feature clients will be able to handle.

mrlubos commented 4 months ago

@mothershipper this is available in the Fetch API client. You can view the demo where I added an example of local client. Would love to hear your thoughts!

mothershipper commented 4 months ago

Appreciate the quick turn-around, I'll give it a shot today!

mothershipper commented 4 months ago

Looks like it'll work, thank you!

One ask -- could @hey-api/client-fetch export the FetchClient interface? Right now I'm using ReturnType<typeof createClient>

mrlubos commented 4 months ago

Sure. I should probably rename it to Client then!

mrlubos commented 4 months ago

@mothershipper Client interface is exported in v0.1.1