@rzymek/codegen-api-client
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

.github/workflows/publish.yml

Optionated uniform configuration for openapi codegen client

Configure all services generated with openapi codegen fetch-typescript template.

Assumtions:

  • Content type is application/json
  • Authentication is Bearer token via header

Install

yarn add @rzymek/codegen-api-client

Setup

import { Configuration } from "api-client/src";
import * as apis from "api-client/src/apis";
import { configureApiClient } from "@rzymek/codegen-api-client";

const api = configureApiClient(apis, Configuration, {
  baseUrl: 'http://api.web.app', 
  bearerToken: async () => globalState.bearerToken,
  onErrorResponse(errorJson) {
      if(errorJson.parameterViolations?.length) {
          thro new ApiValidationError();;
      }
  },
  throwError(msg, error) {
      showNotification(msg);
      throw new Error(msg);
  }
  onNetworking(networking) { updateGlobalState({ networking }) }
});

Usage

const result = api.SampleResourceApi.list()

Readme

Keywords

none

Package Sidebar

Install

npm i @rzymek/codegen-api-client

Weekly Downloads

0

Version

1.0.3

License

MIT

Unpacked Size

7.93 kB

Total Files

5

Last publish

Collaborators

  • rzymek