0.0.11 ‱ Published 4 years ago

@serverless-normalize/normalize v0.0.11

Weekly downloads
5
License
MIT
Repository
github
Last release
4 years ago

serverless-normalize 😎

Build Status Coverage Status

Normalize your serverless functions by abstracting away the differences between the different serverless providers. It adds a standardized request/response model, that you can hook into any framework you like - or use it as is!

The package @serverless-normalize/normalize automatically identifies which provider you are using and if you have the compatibility layer installed for that provider, it'll call your function with the Node.js standard HTTP request and response objects.

Support

Supported Providers

Installation

npm install @serverless-normalize/normalize --save

If you are using AWS or serverless-offline you'll also need the compatibility layer.

npm install @serverless-normalize/aws --save

API

normalize(callback: Function, options?: object): any

The callback has a function signature of:

type Callback = (
  request: http.IncomingMessage,
  response: http.ServerResponse,
) => void

options is optional and depends on the provider. Sensible defaults are used for all the providers.

Examples

With Koa:

// handler.js
import { normalize } from '@serverless-normalize/normalize';
import Koa from 'koa';

const app = new Koa();

app.use(async ctx => {
  ctx.status = 200;
  ctx.body = JSON.stringify({ message: 'Yay!' });
});

export default normalize(app.callback());

FAQ

  • Why the relative require?

    Two reasons: There is no support for "optionalPeerDependencies" in a package.json file - and we don't want to load more code than necessary. And the other reason is because of module bundlers (like Webpack) to still be able to do their analysis and not emit errors or warnings about missing packages (which they would have been if you only include the providers you plan on using). Since scoped packages installs every package under your own scope, this works!

Similar Projects

Contributing

Contributions are more than welcome! Just fork and clone the repository and run npm install.

License

serverless-normalize © Alexander LiljengÄrd. Released under the MIT license. Authored and maintained by Alexander LiljengÄrd with help from contributors.

0.0.11

4 years ago

0.0.9

4 years ago

0.0.8

5 years ago

0.0.7

5 years ago