https://github.com/js-entity-repos/axios
A concrete implementation of js-entity-repos for axios.
https://github.com/js-entity-repos/axios
axios entities javascript library models repository-pattern typescript
Last synced: 9 months ago
JSON representation
A concrete implementation of js-entity-repos for axios.
- Host: GitHub
- URL: https://github.com/js-entity-repos/axios
- Owner: js-entity-repos
- License: gpl-3.0
- Archived: true
- Created: 2017-12-28T14:33:06.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-06-14T13:09:36.000Z (about 5 years ago)
- Last Synced: 2025-09-14T22:56:21.081Z (10 months ago)
- Topics: axios, entities, javascript, library, models, repository-pattern, typescript
- Language: TypeScript
- Size: 1.75 MB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 46
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# axios
> A concrete implementation of js-entity-repos for axios.
### Usage
1. Install it with `npm i @js-entity-repos/axios`.
1. For each entity you will need to do the following.
1. [Create an Entity interface](#entity-interface).
1. [Construct the facade](#construct-the-facade).
1. [Use the facade](https://github.com/js-entity-repos/core/blob/master/docs/facade.md).
Note that you'll probably want to use this with [the Express implementation of js-entity-repos](https://github.com/js-entity-repos/express).
### Entity Interface
```ts
import Entity from '@js-entity-repos/core/dist/types/Entity';
export interface TodoEntity extends Entity {
readonly description: string;
readonly completed: boolean;
}
```
### Construct the Facade
```ts
import factory from '@js-entity-repos/axios/dist/factory';
import axios from 'axios';
const todosFacade = factory({
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',
});
```