Client Core is a libary helping you to create a client RestFul API.
npm install @coaktion/client-core
npm run generate-docs
import {
ClientBasic,
ClientOptions,
defaultClientOptions
} from '@coaktion/client-core';
import { AxiosResponse } from 'axios';
class ApiClient extends ClientBasic {
constructor(baseUrl: string, _options?: ClientOptions) {
super(baseUrl, {
...defaultClientOptions,
endpoints: {
search: '/resources',
fetch: '/resources/:id',
create: '/resources',
update: '/resources/:id',
delete: '/resources/:id'
}
});
}
async custom(id: string): Promise<AxiosResponse> {
return this.makeRequest('GET', '/resources/:id/custom'.replace(':id', 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);
});
Client Core is Copyright.