openapi-typescript-fetch icon indicating copy to clipboard operation
openapi-typescript-fetch copied to clipboard

migrate to http client agnostics

Open reslear opened this issue 3 years ago • 5 comments

hi good job ;)

need feat for use custom http client like axios got

reslear avatar Oct 26 '21 11:10 reslear

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.

ajaishankar avatar Oct 27 '21 00:10 ajaishankar

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 avatar Jan 13 '22 22:01 BeanHeaDza

@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 avatar Jan 14 '22 03:01 ajaishankar

@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).

markandrus avatar Nov 14 '22 15:11 markandrus

This would be a very nice feature.

DenisBessa avatar Jan 03 '24 12:01 DenisBessa