Skip to content

Ultra-light http router work only with decorators and built-in HTTP nodejs module.

License

Notifications You must be signed in to change notification settings

rmingon/http-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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"}]

About

Ultra-light http router work only with decorators and built-in HTTP nodejs module.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published