Corgi
Grape like lightweight HTTP API Framework for AWS Lambda
Example
; // this goes directly into lambda.;
Or refer src/test/e2e/complex_api.ts
How to start
- npm install vingle-corgi
- exports.handler = new Router([routes]).handler();
- deploy lambda
Why do I need an extra Framework for Lambda?
So simple lambda handler looks like this
exports { console; console; ;}
let's say you connected API Gateway, (using serverless maybe), as Lambda Proxy. and built some Restful API with that.
exports { if eventpath === '/api/someapi' && eventmethod == 'GET' else }
Ok, fairly good, since it's on lambda and APIGateway so everything is managed and scaled....etc.
but also you can clearly see that this is at the tipping point of going unmanageable.
there are several frameworks that built for this,
(such as running express itself on lambda, even though which is what exactly AWS APIGateway is for)
lambda-req
aws-serverless-express
serverless-express
At Vingle, we did consider about using these kinds of express wrapping.
But those are really inefficient and not reliable for production usage,
and, most of all, We really thought we can do better.
Inspired by Grape a lot, since we really liked it
Features
- Cascade Routing
- Route parameter
- such as "users/:userId/followings"
- Parameter Validation
- it uses Joi
- Exception Handling
- refer example
- Swagger Document Generation
- View
- Named "Presenter". basically, you return "model" from Route, and "presenter" defines how you convert this model into HTTP resource such as JSON The whole thing supports async/await!, written in typescript from scratch also
Requirements
From v2.0, it only supports lambda nodejs8.10. if you need 6.10 support, either use v1.x or wrap router.handler