Socket
Book a DemoInstallSign in
Socket

@ematipico/middy-request-response

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

@ematipico/middy-request-response

Creates a pair request/response objects from AWS lambda

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

middy-request-response

Creates a request/response objects from API Gateway event.

  • Installation
  • Usage
  • Why
  • Where

Installation

npm i @ematipico/middy-request-response

Or

yarn add @ematipico/middy-request-response

Usage

const middy = require('middy/core');
const requestResponse = require('@ematipico/request-response');

const renderRequest = (event, context) => {
  const { response } = context;

  response.statusCode = 200;
  response.end('<html></html>');
}

const handler = middy(renderRequest)
  .use(requestResponse()) // parses the request body when it's a JSON and converts it to an object

module.exports = { handler }

Why

The reason why I created this package, is that because sometimes it is difficult to unify a lambda environment with a usual server where most of the people are comfortable with.

Most of the times we create a local server inside the lambda.

This middleware wants to mimic the same behaviour without creating a local server. The middleware creates two objects called response and request and will try to mimic as much as possible the behaviours of http.IncomingMessage and
http.ServerResponse.

Where

This middleware can be used in advanced frontend cases where you want to store your pages on a lambda, and you'd need a request and response objects to feed to your frontend frameworks such as Next.js or Nuxt.js.

Keywords

middy

FAQs

Package last updated on 05 May 2020

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