[][src]Crate lambda_http

Enriches the lambda_runtime crate with http types targeting ALB and API Gateway proxy events.

Though ALB and API Gateway proxy events are separate Lambda triggers, they both share similar shapes that contextually map to an http request handler. From a application perspective the differences shouldn't matter. This crate abstracts over both using standard http types allowing you to focus more on your application while giving you to the flexibility to transparently use whichever http trigger suits your application's needs best.

Examples

use lambda_http::{lambda, IntoResponse, Request, RequestExt};
use lambda_runtime::{Context, error::HandlerError};

fn main() {
    lambda!(hello)
}

fn hello(
    request: Request,
    _ctx: Context
) -> Result<impl IntoResponse, HandlerError> {
    Ok(format!(
        "hello {}",
        request
            .query_string_parameters()
            .get("name")
            .unwrap_or_else(|| "stranger")
    ))
}

You can also provide a closure directly to the lambda! macro

use lambda_http::{lambda, Request, RequestExt};

fn main() {
  lambda!(
    |request: Request, context| Ok(
      format!(
        "hello {}",
        request.query_string_parameters()
          .get("name")
          .unwrap_or_else(|| "stranger")
      )
    )
  )
}

Re-exports

pub use http;

Modules

request

ALB and API Gateway request types.

Macros

lambda

A macro for starting new handler's poll for API Gateway and ALB events

Structs

Response

Represents an HTTP response

StrMap

A read-only view into a map of string data which may contain multiple values

Enums

Body

Representation of http request and response bodies as supported by API Gateway and ALBs.

Traits

Handler

Functions serving as ALB and API Gateway handlers must conform to this type.

IntoResponse

A conversion of self into a Response

RequestExt

Extentions for lambda_http::Request structs that provide access to API gateway and ALB features.

Functions

start

Creates a new lambda_runtime::Runtime and begins polling for ALB and API Gateway events

Type Definitions

Request

Type alias for http::Requests with a fixed lambda_http::Body body