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

lambda-api

Package Overview
Dependencies
Maintainers
1
Versions
38
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

to
0.1.0-beta

.travis.yml

9

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

@@ -17,3 +17,8 @@ "main": "index.js",

"awslambda",
"apigateway"
"apigateway",
"web",
"framework",
"json",
"schema",
"open"
],

@@ -20,0 +25,0 @@ "author": "Jeremy Daly <jeremy@jeremydaly.com>",

# lambda-api
**PLEASE NOTE:** This project is still in development and is not ready for production.
**PLEASE NOTE:** This project is still in beta and should be used with caution in production.
[![Build Status](https://travis-ci.org/jeremydaly/lambda-api.svg?branch=master)](https://travis-ci.org/jeremydaly/lambda-api)
[![npm](https://img.shields.io/npm/v/lambda-api.svg)](https://www.npmjs.com/package/lambda-api)
[![npm](https://img.shields.io/npm/l/lambda-api.svg)](https://www.npmjs.com/package/lambda-api)
### Lightweight Node.js API for AWS Lambda

@@ -211,2 +215,12 @@

## Wildcard Routes
Wildcard routes are supported for methods that match an existing route. E.g. `options` on an existing `get` route. As of now, the best use case is for the OPTIONS method to provide CORS headers. Wildcards only work in the base path. `/users/*`, for example, is not supported. For additional wildcard support, use [Path Parameters](#path-parameters) instead.
```javascript
api.options('/*', function(req,res) {
// Do something
res.status(200).send({});
})
```
## Middleware

@@ -219,3 +233,3 @@ The API supports middleware to preprocess requests before they execute their matching routes. Middleware is defined using the `use` method and require a function with three parameters for the `REQUEST`, `RESPONSE`, and `next` callback. For example:

next()
});
})
```

@@ -234,3 +248,3 @@

}
});
})
```

@@ -254,1 +268,21 @@

The API uses Bluebird promises to manage asynchronous script execution. Additional methods such as `async / await` or simple callbacks should be supported. The API will wait for a request ending call before returning data back to the client. Middleware will wait for the `next()` callback before proceeding to the next step.
## CORS Support
CORS can be implemented using the [wildcard routes](#wildcard-routes) feature. A typical implementation would be as follows:
```javascript
api.options('/*', function(req,res) {
// Add CORS headers
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE, OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
res.status(200).send({});
})
```
Conditional route support could be added via middleware or with conditional logic within the `OPTIONS` route.
## Configuring Routes in API Gateway
Routes must be configured in API Gateway in order to support routing to the Lambda function. The easiest way to support all of your routes without recreating them is to use [API Gateway's Proxy Integration](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-set-up-simple-proxy.html#api-gateway-proxy-resource?icmpid=docs_apigateway_console).
Simply create one `{proxy+}` route that uses the `ANY` method and all requests will be routed to your Lambda function and processed by the `lambda-api` module.

@@ -66,3 +66,3 @@ 'use strict'

statusCode: this._statusCode,
body: body
body: typeof body === 'object' ? JSON.stringify(body) : (body && typeof body !== 'string' ? body.toString() : (body ? body : ''))
}

@@ -69,0 +69,0 @@