New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

lambda-api

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lambda-api - npm Package Compare versions

Comparing version 0.1.0-beta to 0.1.0

LICENSE

7

index.js
'use strict';
/**
* Lightweight Node.js API for AWS Lambda
* @author Jeremy Daly <jeremy@jeremydaly>
* @version 0.1.0
* @license MIT
*/
const REQUEST = require('./request.js') // Response object

@@ -4,0 +11,0 @@ const RESPONSE = require('./response.js') // Response object

2

package.json
{
"name": "lambda-api",
"version": "0.1.0-beta",
"version": "0.1.0",
"description": "Lightweight Node.js API for AWS Lambda",

@@ -5,0 +5,0 @@ "main": "index.js",

# lambda-api
**PLEASE NOTE:** This project is still in beta and should be used with caution in production.

@@ -10,4 +9,24 @@ [![Build Status](https://travis-ci.org/jeremydaly/lambda-api.svg?branch=master)](https://travis-ci.org/jeremydaly/lambda-api)

Lambda API is a lightweight Node.js API router for use with AWS API Gateway and AWS Lambda using Lambda Proxy integration. This closely mirrors (and is based on Express.js) but is significantly stripped down to maximize performance with Lambda's stateless, single run executions. The API uses Bluebird promises to serialize asynchronous execution.
Lambda API is a lightweight Node.js API router for use with AWS API Gateway and AWS Lambda using Lambda Proxy integration. This closely mirrors (and is based on) other routers like Express.js but is significantly stripped down to maximize performance with Lambda's stateless, single run executions. The API uses Bluebird promises to serialize asynchronous execution.
## Simple Example
```javascript
const API = require('lambda-api') // API library
// Init API instance
const api = new API({ version: 'v1.0', base: 'v1' });
api.get('/test', function(req,res) {
res.status(200).json({ status: 'ok' })
})
module.exports.handler = (event, context, callback) => {
// Run the request
api.run(event,context,callback);
} // end handler
```
## Lambda Proxy integration

@@ -77,22 +96,2 @@ Lambda Proxy Integration is an option in API Gateway that allows the details of an API request to be passed as the `event` parameter of a Lambda function. A typical API Gateway request event with Lambda Proxy Integration enabled looks like this:

## Simple Example
```javascript
const API = require('lambda-api') // API library
// Init API instance
const api = new API({ version: 'v1.0', base: 'v1' });
api.get('/test', function(req,res) {
res.status(200).json({ status: 'ok' })
})
module.exports.handler = (event, context, callback) => {
// Run the request
api.run(event,context,callback);
} // end handler
```
## Configuration

@@ -149,2 +148,3 @@

- `route`: The matched route of the request
- `requestContext`: The `requestContext` passed from the API Gateway

@@ -254,2 +254,13 @@ The request object can be used to pass additional information through the processing chain. For example, if you are using a piece of authentication middleware, you can add additional keys to the `REQUEST` object with information about the user. See [middleware](#middleware) for more information.

## Clean Up
The API has a built-in clean up method called 'finally()' that will execute after all middleware and routes have been completed, but before execution is complete. This can be used to close database connections or to perform other clean up functions. A clean up function can be defined using the `finally` method and requires a function with two parameters for the REQUEST and the RESPONSE as its only argument. For example:
```javascript
api.finally(function(req,res) {
// close unneeded database connections and perform clean up
})
```
The `RESPONSE` **CANNOT** be manipulated since it has already been generated. Only one `finally()` method can be defined. This uses the Bluebird `finally()` method internally and will execute after properly handled errors as well.
## Error Handling

@@ -256,0 +267,0 @@ The API has simple built-in error handling that will log the error using `console.log`. These will be available via CloudWatch Logs. By default, errors will trigger a JSON response with the error message. If you would like to define additional error handling, you can define them using the `use` method similar to middleware. Error handling middleware must be defined as a function with **four** arguments instead of three like normal middleware. An additional `error` parameter must be added as the first parameter. This will contain the error object generated.

@@ -28,5 +28,4 @@ 'use strict'

// console.log(this.headers);
// console.log(app._event.body);
// console.log('Content-Type', this.headers['Content-Type']);
// Set the requestContext
this.requestContext = app._event.requestContext

@@ -33,0 +32,0 @@ // Set the body

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc