Socket
Socket
Sign inDemoInstall

@everestate/serverless-router

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@everestate/serverless-router

Fast, minimalist, pluggable, universal router.


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

@everestate/serverless-router

Fast, minimalist, pluggable, universal router.

Installation

npm install @everestate/serverless-router --save

Usage

To use serverless-router you will need at least one of its plugins.

  • serverless-router-plugin-web
  • serverless-router-plugin-dynamodb
  • serverless-router-plugin-dynamics
  • and others
const ServerlessRouter = require('@everestate/serverless-router');
const ServerlessRouterWebPlugin = require('@everestate/serverless-router-plugin-web');

const router = new ServerlessRouter([ServerlessRouterWebPlugin]);

router.web
  .get('/users/:userId/appointments', (event, context, callback) => {
    const appointments = findAppointmentsByUserId(event.pathParameters.userId);
    return callback(null, {
      statusCode: '200',
      body: JSON.stringify({ appointments }),
    });
  })
  .post('/users/:userId/appointments', (event, context, callback) => {
    const { userId } = event.pathParameters;
    const appointment = createAppointment({ ...event.body, userId });
    return callback(null, {
      statusCode: '201',
      body: JSON.stringify({ appointment }),
    });
  })
  .delete('/users/:userId/appointments/:appointmentId', (event, context, callback) => {
    const { appointmentId } = event.pathParameters;
    deleteAppointmentById(appointmentId);
    return callback(null, {
      statusCode: '204',
      body: '',
    });
  });
router.dispatch(event, context, callback);

When route is mismatched

By default serverless-router will throw error on route mismatch.

It's possible to define custom mismatch handler, and it would be called with same arguments dispatch was called:

router.mismatch((event, context, callback) => {
  const { path, httpMethod } = event;
  return callback(null, {
    statusCode: '404',
    body: JSON.stringify({ message: `ServerlessRouter can't find the route ${httpMethod} ${path}` }),
  });
});

Plugins

There are few implementations for testing purposes you might be interesting in:

@TODO: describe plugin implementation principles

License

MIT

Keywords

FAQs

Package last updated on 29 May 2018

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