A simple API framework using Flexible Persistence
const pool = new Pool(
((DBHandler.getReadHandler() as ServiceHandler)
.persistence as SequelizeDB).getPersistenceInfo()
);
await Utils.init(pool);
const obj = {};
obj['test'] = 'test';
const handler = DBHandler.getHandler();
const controller = new TestController(DBHandler.getInit());
await ((DBHandler.getReadHandler() as ServiceHandler)
.persistence as SequelizeDB)
.getSequelize()
.models.Test.sync({ force: true });
await handler.getWrite().clear('events');
const sentTest = new Test();
const sentTest2 = new Test();
const store = await controller.store(
({
body: sentTest,
} as unknown) as Request,
(mockResponse as unknown) as Response
);
console.log('store:', store);
- Adapter. Adapts the data to controller and from the controller. Adapting to the selected protocol (like rest or websocket).
- Mid (Middlewares). Middleware is a function that is called before the controller is called. It's possible to use more than one middleware.
- Controller. Controller is what is called when the request is sent to the server. And is responsible for handling the request. It is also responsible for sending the response. As well as formatting the returned response and return codes if needed.
$ npx tmplr judahh/templateAPI
This is a Node.js module available through the npm registry.
Before installing, download and install Node.js.
If this is a brand new project, make sure to create a package.json
first with
the npm init
command or
yarn init
command.
Installation is done using the
npm install
command
or yarn add
command:
$ npm install backAPI
or
$ yarn add backAPI
To run the test suite, first install Docker and dependencies, then run
docker-compose up -d
and npm test
:
$ docker-compose up -d
$ npm install
$ npm test
or
$ docker-compose up -d
$ yarn
$ yarn test
The original author of backAPI is Judah Lima