@js-entity-repos/axios
v6.0.7
Published
A concrete implementation of js-entity-repos for axios.
Downloads
4
Readme
axios
A concrete implementation of js-entity-repos for axios.
Usage
- Install it with
npm i @js-entity-repos/axios
. - For each entity you will need to do the following.
Note that you'll probably want to use this with the Express implementation of js-entity-repos.
Entity Interface
import Entity from '@js-entity-repos/core/dist/types/Entity';
export interface TodoEntity extends Entity {
readonly description: string;
readonly completed: boolean;
}
Construct the Facade
import factory from '@js-entity-repos/axios/dist/factory';
import axios from 'axios';
const todosFacade = factory<TodoEntity>({
axios: async () => axios.create({
baseURL: `http://localhost:80/api/todos`,
}),
constructDocument: (patch) => {
// Optional property that converts an entity to a document for the database.
return patch;
},
constructEntity: (document) => {
// Optional property that converts a document from the database to an entity.
return document;
},
constructFilter: (filter) => {
// Optional property that converts an entity filter to a filter for the DB.
return filter;
},
constructSort: (sort) => {
// Optional property that converts an entity sort to a sort for the DB.
return sort;
},
defaultPaginationLimit: 100, // Optional property.
entityName: 'todo',
});