[][src]Struct srvrls::request::SrvrlsRequest

pub struct SrvrlsRequest {
    pub query_parameters: HashMap<String, Vec<String>>,
    pub path: String,
    pub string_claims: HashMap<String, String>,
    pub integer_claims: HashMap<String, i64>,
    pub method: HttpMethod,
    pub body: String,
}

This replaces the inbound Request and Context entity with simpler, opinionated methods. The data members can be used directly or one of the provided helper functions can simplify access by providing sensible defaults (e.g., empty string) to simplify match statements.

E.g.,


  fn test_handler(request: SrvrlsRequest) -> Result<SrvrlsResponse,SrvrlsError> {
      match (&request.method, request.path_parameter(0).as_str()) {
          (HttpMethod::POST, "customer") => Ok(SrvrlsResponse::no_content()),
          (HttpMethod::POST, "account") => Ok(SrvrlsResponse::created()),
          (HttpMethod::GET, "customer") => Ok(SrvrlsResponse::ok_empty()),
          _ => return Err(SrvrlsError::NotFound)
      }
  }

  let mut request : SrvrlsRequest = Default::default();
  request.method = HttpMethod::POST;
  request.path = "customer/CUST-A23948".to_string();
  assert_eq!(SrvrlsResponse::no_content(), test_handler(request).unwrap());

  let mut request : SrvrlsRequest = Default::default();
  request.method = HttpMethod::POST;
  request.path = "account/ACCT-G10291".to_string();
  assert_eq!(SrvrlsResponse::created(), test_handler(request).unwrap());

  let mut request : SrvrlsRequest = Default::default();
  request.method = HttpMethod::GET;
  request.path = "customer/CUST-A23948".to_string();
  assert_eq!(SrvrlsResponse::ok_empty(), test_handler(request).unwrap());

  let mut request : SrvrlsRequest = Default::default();
  request.method = HttpMethod::GET;
  request.path = "account/ACCT-G10291".to_string();
  assert_eq!(SrvrlsError::NotFound, test_handler(request).unwrap_err());

Fields

query_parameters: HashMap<String, Vec<String>>

All query parameters in a map by key value.

path: String

The path of the request. This is taken from the inbound event field path_parameter for that has the value proxy.

This value is always provided without a leading '/'

string_claims: HashMap<String, String>

All String claims within the authorizer field.

integer_claims: HashMap<String, i64>

All Numeric (i64) claims within the authorizer field.

method: HttpMethod

The HttpMethod of the request.

body: String

The request payload, or empty String if none exists.

Methods

impl SrvrlsRequest[src]

pub fn path_parameter(&self, position: usize) -> String[src]

Provides the path parameter as a String, if the parameter is missing an empty string will be returned in its' stead.


    fn test_handler(request: SrvrlsRequest) -> Result<SrvrlsResponse,SrvrlsError> {
        match (&request.method, request.path_parameter(0).as_str()) {
            (HttpMethod::POST, "customer") => Ok(SrvrlsResponse::no_content()),
            (HttpMethod::POST, "account") => Ok(SrvrlsResponse::created()),
            (HttpMethod::GET, "customer") => Ok(SrvrlsResponse::ok_empty()),
            _ => return Err(SrvrlsError::NotFound)
        }
    }
  let mut request : SrvrlsRequest = Default::default();
  request.path = "customer/update/CUST-A23948".to_string();
  assert_eq!("customer", request.path_parameter(0));
  assert_eq!("update", request.path_parameter(1));
  assert_eq!("CUST-A23948", request.path_parameter(2));

pub fn query_parameter(&self, key: &str) -> Vec<String>[src]

Returns a Vec<String> for a requested query parameter

pub fn authentication_claim(&self, claim: &str) -> String[src]

This provides access to authentication claims (in AWS Lambda Proxy calls) that are Strings. This signature is likely to change with Azure and Google Cloud Function implemenations.

Trait Implementations

impl Default for SrvrlsRequest[src]

impl From<ApiGatewayProxyRequest> for SrvrlsRequest[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,