1.1.3 • Published 2 years ago

serverless-http-utils v1.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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 git@github.com:lemonJS/serverless-http-utils.git

Install dependencies:

$ yarn install

Run the tests:

$ yarn test
1.1.3

2 years ago

1.1.2

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago