mirror of
https://gitlab.com/msrd0/gotham-restful.git
synced 2025-04-20 06:54:46 +00:00
doc & test for RequestBody
This commit is contained in:
parent
aa9fa0f457
commit
e5f13792c6
2 changed files with 72 additions and 4 deletions
|
@ -93,12 +93,31 @@ impl<T : DeserializeOwned> FromBody for T
|
|||
pub struct FromBodyNoError;
|
||||
|
||||
|
||||
/// A type that can be used inside a request body. Implemented for every type that is
|
||||
/// deserializable with serde. If the `openapi` feature is used, it must also be of type
|
||||
/// `OpenapiType`.
|
||||
/**
|
||||
A type that can be used inside a request body. Implemented for every type that is deserializable
|
||||
with serde. If the `openapi` feature is used, it must also be of type [`OpenapiType`].
|
||||
|
||||
If you want a non-deserializable type to be used as a request body, e.g. because you'd like to
|
||||
get the raw data, you can derive it for your own type. All you need is to have a type implementing
|
||||
[`FromBody`] and optionally a list of supported media types:
|
||||
|
||||
```rust
|
||||
# #[macro_use] extern crate gotham_restful;
|
||||
# use gotham_restful::*;
|
||||
#[derive(FromBody, RequestBody)]
|
||||
#[supported_types(mime::IMAGE_GIF, mime::IMAGE_JPEG, mime::IMAGE_PNG)]
|
||||
struct RawImage {
|
||||
content: Vec<u8>,
|
||||
content_type: Mime
|
||||
}
|
||||
```
|
||||
|
||||
[`FromBody`]: trait.FromBody.html
|
||||
[`OpenapiType`]: trait.OpenapiType.html
|
||||
*/
|
||||
pub trait RequestBody : ResourceType + FromBody
|
||||
{
|
||||
/// Return all types that are supported as content types.
|
||||
/// Return all types that are supported as content types. Use `None` if all types are supported.
|
||||
fn supported_types() -> Option<Vec<Mime>>
|
||||
{
|
||||
None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue