Giter Site home page Giter Site logo

lfreneda / responseasy Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 2.0 951 KB

:ok_hand: An easy, simple and elegant http response builder for aws lambda functions with proxy integration.

JavaScript 100.00%
http-response aws-lambda lambda-functions lamda-proxy rest-api gateway-api aws-gateway-api

responseasy's Introduction

ResponsEasy

npm install responseasy --save

๐Ÿ‘Œ An easy, simple and elegant http response builder for aws lambda functions with proxy integration.

Field Control โ™ฅ Maintainability Test Coverage

Built with โค


Why

When working with pure aws lambda functions and proxy integration is always necessary to JSON.stringify payload, manipulate headers, status code and formatting response, which is verbose and nothing clean.

ResponsEasy is an easy, simple and elegant http response builder for aws lambda functions with proxy integration.

Installation

This package is intended for server side use only.

npm install responseasy --save

Usage

Initializing ResponsEasy with default headers:

const res = require('responseasy')({
  headers: { // <-- Default headers 
    'X-Content-Type-Options': 'nosniff',
    'X-XSS-Protection': '1; mode=block',
    'Pragma': 'no-cache',
    'Cache-Control': 'no-store'
  }
})

Returning 200 - OK using named getter ok:

const response = res.ok.json({ name: 'Luiz' })
/*
    {
        statusCode: 200,
        body: '{"name":"Luiz"}',
        headers: {
            'X-Content-Type-Options': 'nosniff',
            'X-XSS-Protection': '1; mode=block',
            Pragma: 'no-cache',
            'Cache-Control': 'no-store'
        }
    }
*/

Returning 400 - Bad Request using named getter badRequest:

const response = res.badRequest.json({ error: true })
/*
    {
        statusCode: 400,
        body: '{"error":true}',
        headers: {
            'X-Content-Type-Options': 'nosniff',
            'X-XSS-Protection': '1; mode=block',
            Pragma: 'no-cache',
            'Cache-Control': 'no-store'
        }
    }
*/

Returning by a custom status code:

const response = res.status(202).json({ id: '1863b459-bebb-4d18-9de5-b6ea857f1627' })
/*
    {
        statusCode: 202,
        body: '{"id":"1863b459-bebb-4d18-9de5-b6ea857f1627"}',
        headers: {
            'X-Content-Type-Options': 'nosniff',
            'X-XSS-Protection': '1; mode=block',
            Pragma: 'no-cache',
            'Cache-Control': 'no-store'
        }
    }
*/


Made with โค

responseasy's People

Contributors

lfreneda avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.