@coaktion/client-core
TypeScript icon, indicating that this package has built-in type declarations

1.10.0 • Public • Published

Client Core

test workflow stale workflow Release Draft workflow

Client Core is a library helping you to create a client RestFul API.

Installation

npm install @coaktion/client-core

Generate docs

npm run generate-docs

Usage

import {
  AxiosClient,
  ClientOptionsAxios,
  converterPathParamsUrl
} from '@coaktion/client-core';
import { AxiosResponse } from 'axios';

class ApiClient extends AxiosClient {
  constructor(clientOptions: ClientOptionsAxios) {
    super(clientOptions);
  }

  async custom(id: string): Promise<AxiosResponse> {
    return this.makeRequest(
      'GET',
      converterPathParamsUrl('/resources/{id}/custom', { id })
    );
  }
}

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

apiClient.search({ query: 'test' }).then((response) => {
  console.log(response.data);
});

apiClient.fetch('123').then((response) => {
  console.log(response.data);
});

apiClient.create({ name: 'test' }).then((response) => {
  console.log(response.data);
});

apiClient.update('123', { name: 'test' }).then((response) => {
  console.log(response.data);
});

apiClient.delete('123').then((response) => {
  console.log(response.data);
});

apiClient.custom('123').then((response) => {
  console.log(response.data);
});

License

Client Core is Copyright.

Author

GitHub

Package Sidebar

Install

npm i @coaktion/client-core

Weekly Downloads

169

Version

1.10.0

License

MIT

Unpacked Size

96.5 kB

Total Files

33

Last publish

Collaborators

  • lmacedo
  • paulovictortinoco
  • aktie