pub enum Body {
Empty,
Text(String),
Binary(Vec<u8>),
}
Representation of http request and response bodies as supported
by API Gateway and ALBs.
These come in three flavors
Empty
( no body )
Text
( text data )
Binary
( binary data )
Body types can be Deref
and AsRef
'd into [u8]
types much like the hyper crate
Body types are inferred with From
implementations.
Types like String
, str
whose type reflects
text produce Body::Text
variants
assert!(match lambda_http::Body::from("text") {
lambda_http::Body::Text(_) => true,
_ => false
})
Types like Vec<u8>
and &[u8]
whose types reflect raw bytes produce Body::Binary
variants
assert!(match lambda_http::Body::from("text".as_bytes()) {
lambda_http::Body::Binary(_) => true,
_ => false
})
Binary
responses bodies will automatically get based64 encoded to meet API Gateway's response expectations.
The unit type ( ()
) whose type represents an empty value produces Body::Empty
variants
assert!(match lambda_http::Body::from(()) {
lambda_http::Body::Empty => true,
_ => false
})
For more information about API Gateway's body types,
refer to this documentation.
A body containing string data
A body containing binary data
Returns the "default value" for a type. Read more
This method tests for self
and other
values to be equal, and is used by ==
. Read more
This method tests for !=
.
Formats the value using the given formatter. Read more
The resulting type after dereferencing.
Serialize this value into the given Serde serializer. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static