@essent/serverless-request-handler
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

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.

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:

    import "reflect-metadata";
  3. class-validator and class-transfrormer are required peer dependencies

    npm install class-validator class-transfrormer --save

  4. 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:

    import "es6-shim";

Readme

Keywords

none

Package Sidebar

Install

npm i @essent/serverless-request-handler

Weekly Downloads

50

Version

2.0.1

License

MIT

Unpacked Size

70.2 kB

Total Files

52

Last publish

Collaborators

  • danny.reijntjens.essent
  • louise.hermosa
  • milosdelgorge
  • tijmen-amsing-essent
  • timo_aerts
  • jesse.schlienkamp.essent
  • essent-cloud-team
  • rduijf
  • jwaarsenburg
  • julian.essent
  • vasilis.bankov_essent.nl
  • janelletavares
  • sgoris-essent
  • azkarmoulana
  • essent.jesse
  • danielkamphorst
  • patrickvangemert
  • fernandesyuri
  • davidvpe
  • ramkrivaseon
  • p33969
  • s69018
  • erikbrgr-essent
  • radurrant
  • veslav
  • mrtnvh
  • jorisdiesvelt
  • ilija_essent
  • wouter.everse.essent.nl
  • m90992
  • niels_essent
  • nl.santhosh.kumar
  • stefanipeters
  • jeroenverhoevenessent
  • thijsvanerp
  • vinodperumal01
  • dmestry
  • panagiotis.doxopoulos
  • nishanthessent
  • ekta123
  • icyrizard
  • thomasessent
  • melihkorkmaz
  • luukpook
  • svloon
  • spike1292
  • rik_bosch_essent
  • wvdkop-essent
  • sharanyasl
  • sreejanarayanankuttty
  • alihabib
  • geert.jan.evers
  • jimfranke1
  • areijngoudt
  • thijsbloks
  • sanjaikumarsankar
  • essent-mobile-app-team
  • jelle-tno
  • jharskamp
  • m71629
  • frwielstra
  • joren-navara
  • thomas_smeele
  • btaluy
  • geert.rutten
  • vincentbitter
  • falcoworkstno
  • cdebruin
  • niek-essent
  • wesley.quintor
  • snorvisable
  • pcmulder
  • jphoiting
  • tomvoigt
  • lmeijdam
  • petervdwal
  • jboeijenga
  • essent-bot
  • vani.anandamurthy
  • jayanti88
  • abhinandan.nasalapure.essent
  • pavandara
  • jeroenvanderlast
  • c.elshof
  • thedcsherman
  • lucashorward
  • hannahmauritz
  • dbeaart
  • tophernl
  • nimitha
  • markdanney
  • sridharsekar
  • mvlagen
  • emielvanrijn
  • n9iels
  • j.miletic
  • koengriffioenessent
  • geert-navara
  • davidfesten
  • lucaclae
  • ui929171
  • m.cetkovic
  • mleen
  • nielsvdhorst
  • stfnvar
  • walkerrunpdx