🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

lambda-serverless-api

Package Overview
Dependencies
Maintainers
1
Versions
401
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lambda-serverless-api

Basic Api Wrapper for Serverless Framework.

1.0.0
Source
npm
Version published
Weekly downloads
892
16.75%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status Test Coverage Greenkeeper badge Dependencies NPM Downloads Semantic-Release Gardener Gitter

Abstraction for Serverless API

This project abstracts the creation of a basic API and the most commonly desired features.

Provides support for:

Install

$ npm install --save lambda-serverless-api

Getting Started

First we need to wrap our lambda endpoint. Inside the lambda function we can then use ApiError and JsonResponse as following:

const api = require("lambda-serverless-api")({
  limiter: {},
  rollbar: {}
});

module.exports = api.wrap(process.env.RATE_LIMIT_PER_IP, () => {
  if (new Date().getHours() === 4) {
    throw new api.ApiError("I am a teapot", 418);
  }
  return new api.JsonResponse({ message: "What's up?" });
});

where RATE_LIMIT_PER_IP allows to set different limits per endpoint. Rate limiting is explained below.

If you want to send plain text instead of json, you can use ApiResponse.

Rate Limiting

Rate limiting uses lambda-rate-limiter. Note that there are some serious restrictions because it does not use centralized storage!

To customize rate limiting, the package options are passed as limiter into the constructor.

Logging Api Errors / Exceptions

To monitor api errors and exceptions lambda-rollbar can be enabled. Options are passed by putting them as rollbar into the constructor.

Keywords

serverless

FAQs

Package last updated on 03 Mar 2018

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