typescript-rest-body-guard
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

BodyGuard for typescript-rest

BodyGuard is a library to use in conjunction with typescript-rest. The library provides a decorator to check if request body data contains all arguments you need.

Installation

Using npm:

$ npm i typescript-rest-body-guard

Or using yarn:

$ yarn add typescript-rest-body-guard

Preconditions

You must provide a DTO class representing your POST data for the request.

// DTOs.ts

export class LoginDTO {
  public constructor(
    public username: string = '',
    public password: string = ''
  ) {}
}

Then you can use it with BodyGuard in your controller:

import { Path, POST } from 'typescript-rest';
import { BodyGuard } from 'typescript-rest-body-guard';

import DTOs from './DTOs';

@Path('/auth')
export default class AuthController {
  @BodyGuard
  @Path('/login')
  @POST
  public login(data: DTOs.LoginDTO) {
    // ...
  }
}

Now request body arguments are guaranteed not to be empty or BodyGuard automatically will return an error to user.

Readme

Keywords

Package Sidebar

Install

npm i typescript-rest-body-guard

Weekly Downloads

0

Version

2.0.1

License

MIT

Unpacked Size

6.75 kB

Total Files

7

Last publish

Collaborators

  • mavedev