openapi-typescript-fetch
openapi-typescript-fetch copied to clipboard
migrate to http client agnostics
hi good job ;)
need feat for use custom http client like axios got
Thanks @reslear. This library's intention is to add fetch.
But will add a fetch property to the config, whereby you can adapt something that uses axios. Similar to useSWR examples here.
Really cool library! Do you accept PRs to help with this change? I was quite sad to learn this library only works on the browser (I'm using node.js).
@BeanHeaDza for node you can use node-fetch
https://github.com/node-fetch/node-fetch/tree/main#providing-global-access
Node CommonJS setup:
// install node-fetch
npm install node-fetch@2
npm install @types/node-fetch@2
// fetch-polyfill.ts
import fetch from 'node-fetch';
import { Headers, Request, Response } from 'node-fetch';
if (!globalThis.fetch) {
globalThis.fetch = fetch as any;
globalThis.Headers = Headers as any;
globalThis.Request = Request as any;
globalThis.Response = Response as any;
}
// index.ts
import './fetch-polyfill'
Will add to README
@ajaishankar what do you think about allowing to provide the fetch
APIs via configure
? This way, we don't have to modify globalThis
and we don't have to make a choice about which fetch
implementation to use globally (we can just set it locally in configure
).
This would be a very nice feature.