Skip to content

Latest commit

 

History

History
43 lines (30 loc) · 935 Bytes

File metadata and controls

43 lines (30 loc) · 935 Bytes

Getting started

Generate a client

npx @fgrzl/fetch-gen --input openapi.yaml --output ./src/adapters/generated.ts

package.json script

{
  "scripts": {
    "gen:api": "npx @fgrzl/fetch-gen --input ./openapi.yaml --output ./src/adapters/generated.ts"
  }
}

Use the adapter

import { createAdapter } from './adapters/generated';
import client from '@fgrzl/fetch';

client.setBaseUrl('https://api.example.com');
const api = createAdapter(client);

const res = await api.getUser({ id: '1' });
if (res.ok) console.log(res.data);

Custom client module

npx @fgrzl/fetch-gen --input openapi.yaml --output ./src/api.ts --instance ./src/custom

Pass a module that exports your preconfigured FetchClient (middleware, auth, retry).

Related