This module aimes to make an interface among all providers about the way of HTTP request/response handling.
This single way is closer to Express syntax.
This module provides a decorator for that.
Providers:
- AWS (Supported)
- Google (Supported)
- Azure (Supported)
- Kubeless (Not yet)
Install
Require Node 6.x at least.
npm install --save serverless-http-interface;
Usage
const httpInterface = ; console// --> e.g "aws" { responsestatus200} exportshandler = ;// or pass the providerName explicitly// exports.handler = httpInterface(handler, 'aws');
How to migrate ?
- Before using it, you will need to maintain your code if you migrate from provider to another ( AWS)
// ((((( Request ))))// With AWSeventqueryStringParameters// With Googlereqquery //... so on// ((((( Response ))))// With AWS// With Azurecontextres = status: 200 body;context
- Now , you have one code base (close to Express syntax) :
// Before exports { } // Nowconst httpInterface = ; { responsestatus200} exportshandler = ;
Now, change the provider (aws, azure, google) and don't worry. The function should be stay the same.
Flexibility
You are still able to access to default arguments according to provider. Those default arguments are available starting for the third index (after "request" and "response" arguments).
For example, if the provider is AWS :
- 3rd argument : event
- 4th argument: context
- 5th argument: callback
If provider is Azure:
- 3rd argument: context
- 4th argument: request
The following example is an AWS Lambda function that leverage both : The interface by using "response" API, and The default by using "event"
const httpInterface = ; { responsestatus200;} exportshandler = ;
Note
We should NOT release without writing unit-tests. But you are welcome to contribute. Nevertheless, the setup of unit-tests framework is done and you have to follow contribution section.
Contribution:
- Tests pass with 80% coverage.
- Test filename convention is "*.spec.js"