http-router-only-decorators
v0.0.2
Published
Ultra-light http router work only with decorators and built-in HTTP nodejs module.
Downloads
2
Readme
Ultra light http router work only with decorators
Install
npm i http-router-only-decorators
Exemple
import {Method, Req, Res, Route} from "http-router-only-decorators";
@Route('/users')
class Users {
users: object[] = []
@Method('PUT', '/:id')
editUsers(req: Req, res: Res) {
res.write(JSON.stringify(req))
return res.end()
}
@Method('POST')
addUsers(req : Req, res: Res) {
this.users.push(req.body)
res.write(JSON.stringify(req.body))
return res.end()
}
@Method('GET')
getUsers(req : Req, res: Res) {
res.write(JSON.stringify(this.users))
return res.end()
}
}
curl --location --request POST '127.0.0.1:8081/users' \
--header 'Content-Type: application/json' \
--data-raw '{
"email": "[email protected]", "password": "test", "name": "test"
}'
curl --location --request GET '127.0.0.1:8081/users'
[{"email": "[email protected]", "password": "test", "name": "test"}]