mirror of
https://github.com/metosin/reitit.git
synced 2025-12-22 18:41:10 +00:00
Better ring coercion docs
This commit is contained in:
parent
e1db177b6c
commit
325b77c56d
3 changed files with 18 additions and 6 deletions
|
|
@ -33,7 +33,7 @@
|
||||||
* [Transforming Middleware Chain](ring/transforming_middleware_chain.md)
|
* [Transforming Middleware Chain](ring/transforming_middleware_chain.md)
|
||||||
* [Middleware Registry](ring/middleware_registry.md)
|
* [Middleware Registry](ring/middleware_registry.md)
|
||||||
* [Default Middleware](ring/default_middleware.md)
|
* [Default Middleware](ring/default_middleware.md)
|
||||||
* [Pluggable Coercion](ring/coercion.md)
|
* [Ring Coercion](ring/coercion.md)
|
||||||
* [Route Data Validation](ring/route_data_validation.md)
|
* [Route Data Validation](ring/route_data_validation.md)
|
||||||
* [Compiling Middleware](ring/compiling_middleware.md)
|
* [Compiling Middleware](ring/compiling_middleware.md)
|
||||||
* [Swagger Support](ring/swagger.md)
|
* [Swagger Support](ring/swagger.md)
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@
|
||||||
["Transforming Middleware Chain" {:file "doc/ring/transforming_middleware_chain.md"}]
|
["Transforming Middleware Chain" {:file "doc/ring/transforming_middleware_chain.md"}]
|
||||||
["Middleware Registry" {:file "doc/ring/middleware_registry.md"}]
|
["Middleware Registry" {:file "doc/ring/middleware_registry.md"}]
|
||||||
["Default Middleware" {:file "doc/ring/default_middleware.md"}]
|
["Default Middleware" {:file "doc/ring/default_middleware.md"}]
|
||||||
["Pluggable Coercion" {:file "doc/ring/coercion.md"}]
|
["Ring Coercion" {:file "doc/ring/coercion.md"}]
|
||||||
["Route Data Validation" {:file "doc/ring/route_data_validation.md"}]
|
["Route Data Validation" {:file "doc/ring/route_data_validation.md"}]
|
||||||
["Compiling Middleware" {:file "doc/ring/compiling_middleware.md"}]
|
["Compiling Middleware" {:file "doc/ring/compiling_middleware.md"}]
|
||||||
["Swagger Support" {:file "doc/ring/swagger.md"}]
|
["Swagger Support" {:file "doc/ring/swagger.md"}]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,16 @@
|
||||||
# Pluggable Coercion
|
# Ring Coercion
|
||||||
|
|
||||||
Basic coercion is explained in detail [in the Coercion Guide](../coercion/coercion.md). With Ring, both request parameters (`:query`, `:body`, `:form`, `:header` and `:path`) and response `:body` can be coerced.
|
Basic coercion is explained in detail [in the Coercion Guide](../coercion/coercion.md). With Ring, both request parameters and response bodies can be coerced.
|
||||||
|
|
||||||
|
The following request parameters are currently supported:
|
||||||
|
|
||||||
|
| type | request source |
|
||||||
|
|-----------|------------------|
|
||||||
|
| `:query` | `:query-params` |
|
||||||
|
| `:body` | `:body-params` |
|
||||||
|
| `:form` | `:form-params` |
|
||||||
|
| `:header` | `:header-params` |
|
||||||
|
| `:path` | `:path-params` |
|
||||||
|
|
||||||
To enable coercion, the following things need to be done:
|
To enable coercion, the following things need to be done:
|
||||||
|
|
||||||
|
|
@ -22,9 +32,11 @@ Coercion can be attached to route data under `:coercion` key. There can be multi
|
||||||
|
|
||||||
## Defining parameters and responses
|
## Defining parameters and responses
|
||||||
|
|
||||||
Parameters are defined in `:parameters` key and responses in `:responses`.
|
Parameters are defined in route data under `:parameters` key. It's value should be a map of parameter `:type` -> Coercion Schema.
|
||||||
|
|
||||||
Below is an example with [Plumatic Schema](https://github.com/plumatic/schema). It defines input schemas for `:query`, `:body` and `:path` parameters and a schema for a successful response `:body`.
|
Responses are defined in route data under `:responses` key. It's value should be a map of http status code to a map which can contain `:body` key with Coercion Schema as value.
|
||||||
|
|
||||||
|
Below is an example with [Plumatic Schema](https://github.com/plumatic/schema). It defines schemas for `:query`, `:body` and `:path` parameters and for http 200 response `:body`.
|
||||||
|
|
||||||
Handler can access the coerced parameters can be read under `:parameters` key in the request.
|
Handler can access the coerced parameters can be read under `:parameters` key in the request.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue