Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,35 @@ router.call(Rack::MockRequest.env_for("/unknown")).status # => 499
### Body Parsers

Rack ignores request bodies unless they come from a form submission.
If we have a JSON endpoint, the payload isn't available in the params hash:
This means some configuration is required for requests that either
include multipart form data, or body text of a different content type.

```ruby
Rack::Request.new(env).params # => {}
__Hanami::Router__ includes a feature enables body parsing for specific MIME Types.
It comes with a built-in multipart form parser, a JSON parser, and also
the ability to pass custom parsers.

#### Multipart Form Parsing

To enable multipart form parameters in Hanami, include the following
code in your `config.ru` file:

```
require "hanami/middleware/body_parser"
use Hanami::Middleware::BodyParser, :form
```

This feature enables body parsing for specific MIME Types.
It comes with a built-in JSON parser and allows to pass custom parsers.
⚠️ **If you're working with file upload forms, you'll almost certainly want to
enable this parser because things will not work as expected otherwise.** ⚠️


#### JSON Parsing

If we have a JSON endpoint, the payload isn't available in the params hash:

```ruby
Rack::Request.new(env).params # => {}
```

```ruby
# frozen_string_literal: true

Expand Down