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

Serverless Router


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

@everestate/serverless-router

Serverless 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 not found

serverless-router has default handler to catch mismatching request. It responds with status 404 and { message: "ServerlessRouter can't find this route" } in the body.

Of course it's possible to define your custom mismatch handler:

router.mismatch((event, context, callback) => {
  const { path, httpMethod } = event;
  console.log(`ServerlessRouter mismatch: ${httpMethod} ${path}`);
  return callback(null, {
    statusCode: '500',
    body: '',
  });
});

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 25 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