Giter Site home page Giter Site logo

lambda-response-template's Introduction

lambda-response-template

npm version Build Status codecov Greenkeeper badge

πŸ’¬ A tiny utility for creating AWS Lambda response objects.

This package provides an easy way for you generate templates for your responses. Increase readability and make your output more consistent across your Lambda application.

Install

npm install lambda-response-template

Features

  • Templating
    • Create re-usable templates for your responses.
  • Transforming
    • Transform your response body before returning it, removing the need to stringify your JSON responses.
  • Fully TypeScript supported

Why

When developing large applications you often work across multiple repositories. I found myself following the same pattern of creating a factory in each repository every time I wanted set standards for a lambda's output. When you also have to add tests for this boilerplate it can quickly get annoying - this package aims to solve this problem by creating a first class, best version of this generic method.

Usage

Set up lambda-response-template with your defaults:

import { ResponseTemplate } from 'lambda-response-template';

const reply = new ResponseTemplate({
  headers: {
    'x-powered-by': 'nodejs',
  }
});

And then use inside your function:

async function handler(event, context) {
  return reply.make(200, body, options);
}

Your response will be made from the template, inheriting any options you set.

Tips

Shortcut for Content-Type header

const a = reply.make(200, body, {
  headers: { 'content-type': 'text/plain' }
});

// can be written as

const b = reply.make(200, body, 'text/plain');

Automatically stringify responses

const reply = new ResponseTemplate({
  transform: (value) => JSON.stringify(value)
})

const response = reply.make(400, {
  theTruth: 'Pizza cutters are a lie!'
});

lambda-response-template's People

Contributors

furudean avatar greenkeeper[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

yakovmeister

lambda-response-template's Issues

An in-range update of @types/node is breaking the build 🚨

The devDependency @types/node was updated from 12.12.1 to 12.12.2.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@types/node is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of ts-node is breaking the build 🚨

The devDependency ts-node was updated from 8.6.1 to 8.6.2.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

ts-node is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • βœ… ci/inspecode/push: 1 issue detected. (Details).
  • ❌ Travis CI - Branch: The build errored.

Release Notes for FIx `yn` Dependency

Fixed

  • Downgrade yn due to node engine (#942)
Commits

The new version differs by 3 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.