Package Exports
- typescript-rest-body-guard
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (typescript-rest-body-guard) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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-guardOr using yarn:
$ yarn add typescript-rest-body-guardPreconditions
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.