Options
All
  • Public
  • Public/Protected
  • All
Menu

@ffflorian/api-client

api-client npm version

A generic API client.

Installation

Run yarn add @ffflorian/api-client or npm install @ffflorian/api-client.

Usage

A complete documentation is available at https://ffflorian.github.io/api-clients/packages/api-client/.

Examples

import {APIClient} from '@ffflorian/api-client';

const apiClient = new APIClient('https://example.com/api/v1');

apiClient.requestService
  .get('/endpoint', {
    headers: {
      Authorization: 'my-api-key',
    },
  })
  .then(data => {
    // ...
  });
import {APIClient} from '@ffflorian/api-client';

const apiClient = new APIClient({
  apiUrl: 'https://example.com/api/v1',
  requestInjector: config => {
    const hawkHeader = hawk.client.header(config.url, config.method, {credentials});
    return {
      ...config,
      headers: {
        Authorization: hawkHeader.header,
      },
    };
  },
});

apiClient.requestService.get('/endpoint').then(data => {
  // ...
});

Build

yarn
yarn dist

Generated using TypeDoc