Skip to content

Commit

Permalink
Fix #50: Add docs about body parsing (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
samdark authored Sep 29, 2024
1 parent 8179c1b commit 011c6e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ composer require yiisoft/input-http

## General usage

Yii Input HTTP allows to have DTO with attributes like this:
Yii Input HTTP allows having DTO with attributes like this:

```php
use Yiisoft\Input\Http\AbstractInput;
Expand Down Expand Up @@ -67,13 +67,17 @@ final class UpdatePostController
}
```

Note that `FromBody` attribute assumes that request body is parsed. If your implementation of request doesn't parse body
automatically, you can use [yiisoft/request-body-parser](https://github.com/yiisoft/request-body-parser) middleware
to prepare it.

Basic steps:

- Configure [storing request](https://github.com/yiisoft/request-provider?tab=readme-ov-file#general-usage).
- Configure [parameters resolver](docs/guide/en/parameters-resolvers.md).
- Create DTO ([request input](docs/guide/en/request-input.md)).
- Mark DTO properties with [hydrator attributes](docs/guide/en/hydrator-attributes.md) provided by this package.
- Add DTO class name as type hint to a class method argument where you want to it to be resolved.
- Add DTO class name as a type hint to a class method argument where you want to it to be resolved.

## Documentation

Expand Down
8 changes: 8 additions & 0 deletions docs/guide/en/hydrator-attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ Here:
- Uploads will be mapped from request's uploaded files;
- Client info will be mapped from request's attribute.

> Note: `Body` attribute assumes that request body is parsed. If your implementation of request doesn't parse body
> automatically, you can use [yiisoft/request-body-parser](https://github.com/yiisoft/request-body-parser) middleware
> to prepare it.
### Customization

By default, request parameters are expected to have the same name as DTO properties. To change that, pass the name
Expand Down Expand Up @@ -114,6 +118,10 @@ final class CreateUserInput

`SearchInput` will be mapped from query parameters, while `CreateUserInput` will be mapped from parsed request body.

> Note: `FromBody` attribute assumes that request body is parsed. If your implementation of request doesn't parse body
> automatically, you can use [yiisoft/request-body-parser](https://github.com/yiisoft/request-body-parser) middleware
> to prepare it.
### Customizing parameter names

Similar to parameter attributes, the names of request's parameters can be customized. Here it's done via a map where
Expand Down

0 comments on commit 011c6e8

Please sign in to comment.