1.0.0 • Published 2 years ago

cabbage-expressv2 v1.0.0

Weekly downloads
-
License
ISC
Repository
bitbucket
Last release
2 years ago

Cabbage-Express

Cabbage-Express is a library to quickly build controller based express applications.

Included Dependencies

PackageVersion
Express4.17.3
Body-Parser1.19.2
TypeDi0.10.0
Reflect-Metadata0.1.13

Example

$ npm install cabbage-express

import { CabbageApi } from 'cabbage-express'

const api = Container.get(CabbageApi)

api.configureMiddleware()
.mapControllers([
    [AuthController, new AuthController()]
])
.mapEndpoints()
.listen(process.env.PORT, () => console.log(`Listening on port ${process.env.PORT}`))
Controller
@ControllerRoute("/auth")
export default class AuthController {

    // Defines a GET request with no middleware
    @HttpGet("/login")
    async login(req: Request, res: Response) {
        ...
    }

    // Defines a POST request with the `isLoggedIn` middleware.
    @HttpPost("/change_password", isLoggedIn)
    async changePassword(req: Request, res: Response) {
        ...
    }
}
Generated endpoints

GET /auth/login POST /auth/change_password

Contributing

Anyone is welcomed to contribute to Cabbage-Express. Simply clone down the repository and submit a pull-request of your desired changes.