# serverless-request-handler

> A request handler that uses class-transformer and class-validator to create a type-safe serverless handler!

Latest version **1.5.0** (published 2020-10-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install serverless-request-handler
pnpm add serverless-request-handler
yarn add serverless-request-handler
bun add serverless-request-handler
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.5.0 |
| Published | 2020-10-27 |
| First published | 2019-11-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 51.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Ruben v. Rooij |
| Maintainers | ruben.van.rooij |

## Links

- npm: https://www.npmjs.com/package/serverless-request-handler
- Repository: https://github.com/rubenvanrooij/serverless-request-handler
- Homepage: https://github.com/rubenvanrooij/serverless-request-handler#readme
- Issues: https://github.com/rubenvanrooij/serverless-request-handler/issues
- npm.io page: https://npm.io/package/serverless-request-handler

## Dependencies (5)

- [winston](https://npm.io/package/winston.md) ^3.2.1
- [aws-lambda](https://npm.io/package/aws-lambda.md) ^1.0.5
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13
- [http-status-codes](https://npm.io/package/http-status-codes.md) ^1.4.0
- [class-validator-jsonschema](https://npm.io/package/class-validator-jsonschema.md) ^1.3.0

## Recent versions

- 1.5.0 (latest) — 2020-10-27
- 1.4.0 — 2020-06-25
- 1.3.0 — 2019-12-10
- 1.2.1 — 2019-12-02
- 1.2.0 — 2019-11-28
- 1.1.2 — 2019-11-27
- 1.1.1 — 2019-11-27
- 0.0.0-development — 2019-11-27
- 1.0.0 — 2019-11-27
- 0.1.7 — 2019-11-26
- 0.1.6 — 2019-11-26
- 0.1.5 — 2019-11-26
- 0.1.4 — 2019-11-26
- 0.1.3 — 2019-11-26
- 0.1.2 — 2019-11-26
- … 2 more at https://npm.io/package/serverless-request-handler/versions

## README

# serverless-request-handler
A request handler that uses class-transformer and class-validator to create a type-safe serverless handler

## What is serverless-request-handler
Serverless request handler is a micro-framework that's here to make your life easier. You give it an options object with what you expect the request to look like; and it does the object request transformation, request validation, response validation and error handdling. 

A typical handler will look like this.
```typescript

class CreateUserDto {
    @IsEmail()
    userName: string;

    @IsString()
    @MinLength(7)
    password: string;
}

class UserPathParams {
    @IsNumber()
    userId: number;
}

const options = {
    body: {
        classType: CreateUserDto
    },
    pathParameters: {
        classType: UserPathParams
    }
};


const createUser = handler(options, async (event) => {
    return Result.Ok(201, userService.create(event.pathParameters.userId, event.body));
});

```

## Installation

1. Install module:

    `npm install serverless-request-handler --save`

2. `reflect-metadata` shim is required, install it too:

    `npm install reflect-metadata --save`

    and make sure to import it in a global place, like server.ts:

    ```typescript
    import "reflect-metadata";
    ```

3. `class-validator` and `class-transfrormer` are required peer dependencies

    `npm install class-validator class-transfrormer  --save`

3. ES6 features are used, if you are using old version of node.js you may need to install es6-shim:

   `npm install es6-shim --save`

   and import it in a global place like app.ts:

    ```typescript
    import "es6-shim";
    ```

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