@coaktion/client-core
v1.10.0
Published
Library helping you to create a client RestFul API
Downloads
285
Readme
Client Core
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.