-
-
Notifications
You must be signed in to change notification settings - Fork 525
[openapi-fetch] Provide client.request()
to support dynamic method.
#1808
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
client.request()
to provide dynamic method.client.request()
to support dynamic method.
I’d be open to adding this! This should be pretty invisible. There’s no strong reason this wasn’t done initially. But one trickiness in all this will be requiring (or denying) requestBody based on the method. We’ll need lots of type tests to make sure this catches everything (negative type tests are as valuable as—if not moreso—positive type tests). But adding this should be very doable and shouldn’t impact performance at all. |
I’d be open to adding this as well! In the case where we need to isolate the backend for security reasons, we will make an api proxy on the React server side, so that all client's query goes through the api proxy to make the request. In the case where openapi-fetch is to be executed in the proxy instead of directly on the client, request method should be passed as a variable to achieve a generic proxy. In this usage scenario, there is also the problem of not being able to dynamically assign a value to path parameter, because of its PathsWithMethod type definition. Perhaps the dynamic assignment of path can be achieved by throwing an error when path doesn't match paths with methods, while balancing the efficiency of checking with PathsWithMethod. |
I have been trying to implement const mth = method.toUpperCase() as keyof typeof client;
const fn = client[mth] as ClientMethod<Paths, typeof method, Media>; Could you provide a full example with |
Description
Currently,
openapi-fetch
uses the method as the function name (ex:client.GET()
) and there is no way to use the method as an argument. When building aroundopenapi-fetch
it requires a bit of gymnastic and manual typing to have a dynamic method.We can also find this pattern in libraries like axios, ky, etc.
Proposal
Internally,
openapi-fetch
already usecoreFetch
method to pass the method as an argument.We could have a
request
(orREQUEST
to respect casing) method on the client. (orFETCH
).Checklist
The text was updated successfully, but these errors were encountered: