5.0.0 • Published 2 years ago
@ionaru/micro-web-service v5.0.0
@ionaru/micro-web-service
Description
A library with tools to quickly create an express server.
Usage
npm install @ionaru/micro-web-service ajv ajv-errors ajv-formats
npm install -D @types/body-parser @types/compression @types/express @types/express-serve-static-core
export class ExampleRouter extends BaseRouter {
// request: express.Request
// response: express.Response
// next: express.NextFunction
static badHandler(request, response, next) {
ExampleRouter.sendResponse(response, 400, 'Bad');
}
static okHandler(request, response, next) {
ExampleRouter.sendSuccess(response);
}
static dataHandler(request, response, next) {
ExampleRouter.sendSuccess(response, {value: 5});
// Data can be anything.
// Responds {data: {value: 5}, message: 'OK', state: 'success'}
}
constructor() {
super();
this.createRoute('get', '/bad', ExampleRouter.badHandler);
this.createRoute('get', '/ok', ExampleRouter.okHandler.bind(this)); // Bind class context.
this.createRoute('get', '/data', ExampleRouter.dataHandler);
}
}
const router = new ExampleRouter();
const serviceController = new ServiceController({
port: 3000,
routes: [
['/', router],
],
}).listen().then();
// Close the webserver
serviceController.close().then();
4.2.1-5.0
2 years ago
4.2.1-4.0
2 years ago
4.2.1-6.0
2 years ago
4.2.1-1.0
2 years ago
5.0.0
2 years ago
4.2.1-3.0
2 years ago
5.0.1-8.0
2 years ago
4.0.1-28.0
3 years ago
4.1.1-31.0
3 years ago
4.2.1-32.0
3 years ago
4.1.0
3 years ago
4.0.0
3 years ago
4.2.0
3 years ago
3.0.3-27.0
3 years ago
3.0.3-25.0
3 years ago
3.0.2
3 years ago
3.0.1
3 years ago
3.0.2-24.0
3 years ago
3.0.1-22.0
3 years ago
3.0.0
3 years ago
2.0.1-19.0
3 years ago
3.0.1-20.0
3 years ago
1.0.1-16.0
3 years ago
2.0.1-17.0
3 years ago
2.0.0
3 years ago
1.0.1-15.0
4 years ago
1.0.1-14.0
4 years ago
1.0.1-13.0
4 years ago
1.0.1-12.0
4 years ago
1.0.1-11.0
4 years ago
1.0.0
4 years ago
0.0.2-6.0
4 years ago
1.0.1-7.0
4 years ago
0.0.2-5.0
4 years ago
0.0.2-4.0
4 years ago
0.0.2-3.0
4 years ago
0.0.1
4 years ago
0.0.2-2.0
4 years ago