0.2.0 • Published 1 year ago
express-routings v0.2.0
express-routings
Allows to create controller classes with methods as actions that handle express requests.
Installation
Install module:
npm i express-routings
Install
reflect-metadata
npm install reflect-metadata
Make sure
reflect-metadata
to import beforeexpress-routings
import 'reflect-metadata'
Usage
Example of usage
Create a file
UserController.ts
import { Controller, Param, Body, Get, Post, Put, Delete } from 'express-routings'; @Controller() export class UserController { @Get('/users') getAll() { return 'This action returns all users'; } @Get('/users/:id') getOne(@Param('id') id: number) { return 'This action returns user #' + id; } @Post('/users') post(@Body() user: any) { return 'Saving user...'; } @Put('/users/:id') put(@Param('id') id: number, @Body() user: any) { return 'Updating a user...'; } @Delete('/users/:id') remove(@Param('id') id: number) { return 'Removing user...'; } }
This class will register routes specified in method decorators in express.js framework.
Create a file
app.ts
import 'reflect-metadata' import { createServer } from 'routing-controllers'; import { UserController } from './UserController'; const app = createServer({ controllers: [UserController], // we specify controllers we want to use }); // run express application on port 3000 app.listen(3000);
0.2.0
1 year ago
0.1.9
2 years ago
0.1.8
2 years ago
0.1.7
3 years ago
0.1.4
3 years ago
0.1.3
3 years ago
0.1.6
3 years ago
0.1.5
3 years ago
0.1.2
3 years ago
0.1.1
3 years ago
0.1.0
3 years ago
0.0.9
3 years ago
0.0.8
3 years ago
0.0.7
3 years ago
0.0.6
3 years ago
0.0.5
3 years ago
0.0.4
3 years ago
0.0.3
3 years ago
0.0.2
3 years ago
0.0.1
3 years ago