Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hapi-decorators

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapi-decorators

Decorators for HapiJS routes. Heavily inspired and borrowed from https://github.com/stewartml/express-decorators

  • 0.2.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7K
increased by81.23%
Maintainers
1
Weekly downloads
 
Created
Source

hapi-decorators

Decorators for HapiJS routes. Heavily inspired and borrowed from https://github.com/stewartml/express-decorators

Great to mix with https://github.com/jayphelps/core-decorators.js

npm version Build Status Coverage Status

Usage

npm install --save hapi-decorators
import {
  controller,
  get
} from 'hapi-decorators'

@controller('/hello')
public class TestController {
  constructor(target) {
    this.target = target
  }

  @get('/world')
  sayHello(request, reply) {
    reply({ message: `hello, ${this.target}` })
  }
}

let test = new TestController('world')

server.routes(test.routes())

Decorators

@controller(basePath)

REQUIRED This decorator is required at the class level, since it processes the other decorators, and adds the instance.routes() function, which returns the routes that can be used with Hapi, e.g. server.routes(users.routes()).

@route(method, path)

This decorator should be attached to a method of a class, e.g.

@controller('/users')
class Users {
  @route('post', '/')
  newUser(request, reply) {
    reply([])
  }
}

Helper Decorators

  • @get(path)
  • @post(path)
  • @put(path)
  • @patch(path)
  • @delete(path)
  • @all(path)

These are shortcuts for @route(method, path) where @get('/revoke') would be @route('get', '/revoke').

@validate(config)

Add a validation object for the different types, except for the response. config is an object, with keys for the different types, e.g. payload.

TODO

  • @config - Passing a whole config, solution that would encompase all future decorators in a crude way. Most control to the user.
  • @auth - Handy auth, without doing the whole config.
  • @cache
  • more..

Keywords

FAQs

Package last updated on 08 Sep 2015

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc