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

@middy/core

Package Overview
Dependencies
Maintainers
10
Versions
226
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@middy/core

šŸ›µ The stylish Node.js middleware engine for AWS Lambda (core package)

  • 1.0.0-alpha.47
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
316K
decreased by-26.14%
Maintainers
10
Weekly downloads
Ā 
Created

What is @middy/core?

@middy/core is a middleware engine for AWS Lambda that helps you simplify and streamline your Lambda functions by allowing you to compose them using reusable middleware. It provides a way to handle common concerns such as input validation, error handling, and response formatting in a modular and reusable manner.

What are @middy/core's main functionalities?

Middleware Composition

This feature allows you to compose your Lambda function using multiple middleware. Each middleware can perform specific tasks and then pass control to the next middleware in the chain.

const middy = require('@middy/core');
const middleware1 = (request, next) => { console.log('Middleware 1'); next(); };
const middleware2 = (request, next) => { console.log('Middleware 2'); next(); };
const handler = middy((event, context) => { return { message: 'Hello World' }; })
  .use(middleware1)
  .use(middleware2);

exports.handler = handler;

Error Handling

This feature allows you to handle errors in a centralized manner. The errorHandler middleware catches any errors thrown by the Lambda function and sets a custom response.

const middy = require('@middy/core');
const errorHandler = (request, next) => { try { next(); } catch (err) { console.error(err); request.response = { statusCode: 500, body: 'Internal Server Error' }; } };
const handler = middy((event, context) => { throw new Error('Something went wrong'); })
  .use(errorHandler);

exports.handler = handler;

Input Validation

This feature allows you to validate the input to your Lambda function. The inputValidator middleware checks if the input is valid and throws an error if it is not.

const middy = require('@middy/core');
const inputValidator = (request, next) => { if (!request.event.body) { throw new Error('Invalid input'); } next(); };
const handler = middy((event, context) => { return { message: 'Input is valid' }; })
  .use(inputValidator);

exports.handler = handler;

Other packages similar to @middy/core

Keywords

FAQs

Package last updated on 17 Oct 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

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