Skip to content

Commit

Permalink
Update readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Rokt33r committed Mar 21, 2019
1 parent 96f3d32 commit 4798ccf
Showing 1 changed file with 3 additions and 44 deletions.
47 changes: 3 additions & 44 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,43 +261,7 @@ We also provide `reqHeaders`, `reqCookies` and `reqSession` for `req.headers`, `

#### Body validation

`@reqBody` supports validation via `class-validator`.

Please install `class-validator` package first.

```sh
npm install class-validator
```

```ts
import { IsString } from 'class-validator'

class PostDTO {
@IsString()
title: string

@IsString()
content: string
}


@controller('/posts')
class PostController() {
@httpPost('/')
// Tachijs can access `PostDTO` via reflect-metadata.
async create(@reqBody() body: PostDTO) {
// `body` is already validated and transformed into an instance of `PostDTO`.
// So we don't need any extra validation.
const post = await Post.create({
...body
})

return {
post
}
}
}
```
It has been deprecated from v1. We'll provide this feature as a separated module.

#### Custom parameter decorators!

Expand Down Expand Up @@ -513,8 +477,6 @@ class HomeController {
}
```

> `#httpContext`, `#inject` and `#injector` will be deprecated from v1.0.0. Please use `#context`
#### Customize result

If you want to have customized result behavior, you can do it with `BaseResult`.
Expand Down Expand Up @@ -862,20 +824,17 @@ interface HandlerParamMeta<T> {
- `selector` Its selector.
- `paramType` metadata from `design:paramtypes`.

#### `@reqBody(validator?: any)`
#### `@reqBody()`

Inject `req.body`.

- `validator` Optional. A class with decorators of `class-validator`. tachijs will validate `req.body` with it and transform `req.body` into the validator class. If `validator` is not given but the parameter has a class validator as its param type, tachijs will use it via `reflect-metadata`.

```ts
import { controller, httpPost, reqBody } from 'tachijs'

@controller('/post')
class PostController {
@httpPost('/')
// Identically same to `create(@reqBody(PostDTO) post: PostDTO)`
create(@reqBody() post: PostDTO) {
create(@reqBody() post: any) {
...
}
}
Expand Down

0 comments on commit 4798ccf

Please sign in to comment.