npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-http-decorators

v1.1.0

Published

Decorator typescript for express controlers/router

Downloads

1

Readme

Total alerts Language grade: JavaScript

express-http-decorators

Decorator typescript for express controlers/router

If you don't known about HTTP methods see HTTP request methods at MDN

How to use

// Controller example

import { Request, Response } from 'express'
import { ControllerBase, Controller, Get } from 'express-http-decorators';

@Controller() // /example
export class Example extends ControllerBase {
    @Get({ path: '/world' }) // /example/world
    world(request: Request, response: Response) {
        response.send('Hello World');
    }

    @Post({ path: '/hello' }) // /example/hello
    hello(request: Request, response: Response) {
        response.send('Hello World');
    }
}

export default Example;
// Express app example

import express, { Router } from 'express';
import { autoloader } from 'express-http-decorators';
import Example from './controllers/Example';

const app = express();

app.use(autoloader([Example], Router()))

app.listen(8888, () => {
    console.log('Express http decorator on air at 127.0.0.1:8888')
})

Functions

Function to load and make endpoint

  • autoloader(array: Array<class extends ControlerBase>, router: Express.Router, verbose: (ResourceIdentifier) => void): Express.Router: This function recives an array of class "controller" that extends ControlerBase and bind to router of express
    • array: Array<class extends ControlerBase>: Array of class that extends ControllerBase
    • router: Express.Router: The router of express
    • verbose: (ResourceIdentifier) => void: Function callback that is call every new endpoint binded to router (for debug)

HTTP methods decorators available: Post, Get, Put, Patch, Delete

  • @<decorator name>(methodParameters?: MethodParameters): With this decorator you can make a method at class as endpoint
    • MethodParameters.path: Custom name to endpoint, if not setted, will be the name of class method
    • MethodParameters.middleware: Array of middlewares express

Decorator for class controller. The class controller aways must be extends ControllerBase.

  • @Controller(name?: string): This decorator defines the base name to endpoint see example above, if not setted, will be the name of class

For development or test

    1. Download the repository
    1. npm install To install dependecies
    1. npm link && npm link express-http-decorators To link this project as module in node_modules directory
    1. npm run dev To run code in example directory

Founders

License

MIT