Skip to content

Creates a request/response objects from API Gateway event

License

Notifications You must be signed in to change notification settings

ematipico/middy-request-response

Repository files navigation

middy-request-response

Creates a request/response objects from API Gateway event.

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.

About

Creates a request/response objects from API Gateway event

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published