# serverless-http-utils

> Serverless HTTP utils

Latest version **1.1.3** (published 2022-01-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install serverless-http-utils
pnpm add serverless-http-utils
yarn add serverless-http-utils
bun add serverless-http-utils
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.3 |
| Published | 2022-01-11 |
| First published | 2021-03-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 17 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Lewis Monteith |
| Maintainers | lemonjs |

## Links

- npm: https://www.npmjs.com/package/serverless-http-utils
- Repository: https://github.com/lemonJS/serverless-http-utils
- Homepage: https://github.com/lemonJS/serverless-http-utils#readme
- Issues: https://github.com/lemonJS/serverless-http-utils/issues
- npm.io page: https://npm.io/package/serverless-http-utils

## Recent versions

- 1.1.3 (latest) — 2022-01-11
- 1.1.2 — 2021-07-06
- 1.1.0 — 2021-03-20
- 1.0.0 — 2021-03-18

## 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
```shell
$ 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`:
```typescript
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`:
```typescript
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:
```shell
$ git clone git@github.com:lemonJS/serverless-http-utils.git
```
Install dependencies:
```shell
$ yarn install
```
Run the tests:
```shell
$ yarn test
```

---
_Source: https://npm.io/package/serverless-http-utils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
