🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

perd

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

perd

Powerful Express Router Decorators

latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

PERD

Create your clean, simple, and readable express router only use typescript decorators

Documentation for PERD (Powerful Express Router Decorators)

Installation

NPM

npm install perd

Yarn

yarn add perd

Features

  • Robust routing
  • Clean and Readable Route

Basic Usage

hello-controller.ts

import { BaseController, ErrorHandler, GET, POST, router } from 'perd'
@router('/hello')
export class HelloController extends BaseController {
  /**
   * you can define your route so simple like this
   * @param data - data that already bundled from `req.params` `req.query`
   */
  @GET('/sayHello/:name')
  async sayHelloWithQuery(data: { name: string }) {
    return `Hello ${data.name}`
  }

  /**
   * if you not provide the path, it will automatically set by
   * the function name `sayHello`
   */
  @GET()
  async sayHello() {
    return 'Hello World'
  }

  @POST('/message')
  async createMessage(data: { message: string }) {
    if (!data.message) {
      // if you want to throw an error just simply throw an error handler
      throw new ErrorHandler(403, "You're not provide the message", true)
    }
  }
}

app.ts

import express from 'express'
import { HelloController } from './controllers'

const app = express()
app.use(HelloController.routers())
app.listen(3000, () => {
  console.log('yeaay!! your express server already running on port ', 3000)
})

Keywords

decorators

FAQs

Package last updated on 20 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts