Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/djgrant/aws-lambda-express
Express style routing for AWS lambda
https://github.com/djgrant/aws-lambda-express
Last synced: about 2 months ago
JSON representation
Express style routing for AWS lambda
- Host: GitHub
- URL: https://github.com/djgrant/aws-lambda-express
- Owner: djgrant
- Created: 2018-04-03T10:03:15.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-04-03T17:08:00.000Z (almost 7 years ago)
- Last Synced: 2024-11-01T22:36:51.713Z (3 months ago)
- Language: JavaScript
- Size: 49.8 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# aws-lambda-express
Express style routing for AWS Lambda.
The library provides a similar API to Express, with the difference of being backed by Lambda's event and context objects, rather than the HTTP module.
## Installation
The project is still a WIP so I have not published to NPM yet.
## Usage
```js
const Router = require("aws-lambda-express");const router = new Router();
router.use((req, res, next) => {
console.log(req.event);
console.log(req.context);
next();
});router.use("/some/route", (req, res, next) => {
res
.set({ "my-header": "hello" })
.status(200)
.send("Hello world");
});const handler = (event, context, cb) => {
router
.handle(event, context)
.then(response => {
cb(null, {
body: response.body,
headers: response.headers,
statusCode: response.statusCode
});
})
.catch(err) => {
cb(err);
});
};module.exports = handler;
```## API
For now, please refer to the tests in [test/router.test.js](./test/router.test.js) for a complete API reference.
## Todo
* [] HTTP methods
* [] Docs
* [] Publish to NPM