serverless-http-utils
v1.1.3
Published
Serverless HTTP utils
Downloads
7
Readme
Serverless HTTP Utils
A small utils package that simplifies REST handlers inside Serverless APIs.
Requirements
- A Serverless API using node v14 or later
- ApiGateway configured to use the v2 event
Installation
$ yarn add serverless-http-utils
or
$ npm install serverless-http-utils
Usage
Wrap any exported Serverless handler with the handler
method and return a new instance of HttpSuccess
:
import { handler, Event, HttpSuccess } from 'serverless-http-utils';
export const handle = handler((event: Event) => {
return new HttpSuccess(200, { hello: 'world' });
});
Errors can be thrown anywhere by throwing a HttpException
:
import { HttpException } from 'serverless-http-utils';
async function authenticate(token: string): void {
if (!token) {
throw new HttpException(401, 'Token not provided');
}
}
See the example/
folder for more info.
Contributing
Clone the repository:
$ git clone [email protected]:lemonJS/serverless-http-utils.git
Install dependencies:
$ yarn install
Run the tests:
$ yarn test