@js-entity-repos/axios

6.0.7 • Public • Published

axios

A concrete implementation of js-entity-repos for axios.

Usage

  1. Install it with npm i @js-entity-repos/axios.
  2. For each entity you will need to do the following.
    1. Create an Entity interface.
    2. Construct the facade.
    3. Use the facade.

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',
});

Readme

Keywords

none

Package Sidebar

Install

npm i @js-entity-repos/axios

Weekly Downloads

0

Version

6.0.7

License

GPL-3.0

Unpacked Size

91.2 kB

Total Files

39

Last publish

Collaborators

  • ryansmith94