[−][src]Trait lambda_http::RequestExt
Extentions for lambda_http::Request
structs that
provide access to API gateway
and ALB
features.
Examples
You can also access a request's body in deserialized format
for payloads sent in application/x-www-form-urlencoded
or
application/x-www-form-urlencoded
format
#[macro_use] extern crate lambda_http; extern crate lambda_runtime as lambda; #[macro_use] extern crate serde_derive; use lambda::{Context, error::HandlerError}; use lambda_http::{Body, Request, Response, RequestExt}; #[derive(Debug,Deserialize,Default)] struct Args { #[serde(default)] x: usize, #[serde(default)] y: usize } fn main() { lambda!(handler) } fn handler( request: Request, ctx: lambda::Context ) -> Result<Response<Body>, HandlerError> { let args: Args = request.payload() .unwrap_or_else(|_parse_err| None) .unwrap_or_default(); Ok( Response::new( format!( "{} + {} = {}", args.x, args.y, args.x + args.y ).into() ) ) }
Required methods
fn query_string_parameters(&self) -> StrMap
Return pre-parsed http query string parameters, parameters
provided after the ?
portion of a url,
associated with the API gateway request.
The yielded value represents both single and multi-valued
parameters alike. When multiple query string parameters with the same
name are expected, query_string_parameters().get_all("many")
to retrieve them all.
No query parameters
will yield an empty StrMap
.
fn path_parameters(&self) -> StrMap
Return pre-extracted path parameters, parameter provided in url placeholders
/foo/{bar}/baz/{boom}
,
associated with the API gateway request. No path parameters
will yield an empty StrMap
These will always be empty for ALB triggered requests
fn stage_variables(&self) -> StrMap
Return stage variables
associated with the API gateway request. No stage parameters
will yield an empty StrMap
These will always be empty for ALB triggered requests
fn request_context(&self) -> RequestContext
Return request context data assocaited with the ALB or API gateway request
fn payload<D>(&self) -> Result<Option<D>, PayloadError> where
D: Deserialize<'de>,
D: Deserialize<'de>,
Return the Result of a payload parsed into a serde Deserializeable type
Currently only application/x-www-form-urlencoded
and application/json
flavors of content type
are supported
A PayloadError will be returned for undeserializable
payloads. If no body is provided, Ok(None)
will be returned.
Implementations on Foreign Types
impl RequestExt for HttpRequest<Body>
[src]
impl RequestExt for HttpRequest<Body>
fn query_string_parameters(&self) -> StrMap | [src] |
fn path_parameters(&self) -> StrMap | [src] |
fn stage_variables(&self) -> StrMap | [src] |
fn request_context(&self) -> RequestContext | [src] |
fn payload<D>(&self) -> Result<Option<D>, PayloadError> where | [src] |