New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@bakeryjs/router

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

@bakeryjs/router

Node.js HTTP Router for handling requests and performing responses

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

bakeryjs/router

Installation

Install library via npm:

$ npm install @bakeryjs/router

How to use

Create a new router:

const router = require('./router')();

// or (if it's needed to use different routers that will be isolated from each other)

const Router = require('./router');
const router = Router();

Configure route (endpoint) and it's handler:

router
  .handle('/authors/:authorId/books', createBook)
  .method('POST')
  .provideReqRes(true)
  .sendResponse(false);

Set handler for http server:

const server = http.createServer(router.handler);

API reference

Router:

  • (method) handle: (pattern: string, handler: function) - register endpoint and it's handler

NOTE: use ':' symbol to indicate a query parameter.

  • (property) handler: function - get http handler

Route:

  • (method) method(value: string) - set HTTP method for route (GET by default)
  • (method) provideReqRes(value: boolean) - provide req and res objects to handler function (false by default)
  • (method) sendResponse(value: boolean) - send response with function return value (true by default)

NOTE: if it's needed to send custom response from hanlder the provideReqRes should be true to get req object and use it to prepare and send response.

Demo

Take a look on demo project.

Keywords

FAQs

Package last updated on 14 May 2022

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