vicuna

Crates.iovicuna
lib.rsvicuna
version0.4.1
sourcesrc
created_at2019-12-12 16:26:22.286203
updated_at2020-01-09 03:13:08.202269
descriptionAWS Lambdas made simple.
homepagehttps://github.com/PocketDerm/vicuna
repositoryhttps://github.com/PocketDerm/vicuna
max_upload_size
id188815
size17,698
Max Countryman (maxcountryman)

documentation

https://docs.rs/vicuna

README

Vicuna

GitHub Actions crates.io Released API docs MIT licensed

AWS Lambdas in Rust made simple.

  • Simple, middleware-based interface
  • Naturally modular design
  • Purpose-built for serverless-rust

⚠️ Active Development: Vicuna's API has not stabalized and may change without warning between releases!

📦 Install

Add the following to your Cargo.toml file.

[dependencies]
vicuna = "0.4.1"

🤸 Usage

💡 This crate is intended to be paired with the serverless-rust plugin.

Vicuna produces handlers which take in a Lambda request and produce an appropriate response. The simplest handler is the default_handler provided by the crate:

use vicuna::{default_handler, lambda_http::lambda};

fn main() {
    lambda!(default_handler())
}

Handlers can be composed from middleware which can handle the request-response lifecycle in an arbitrary fashion. For example, custom middleware can be written like so:

use vicuna::Handler;

fn my_middleware(handler: Handler) -> Handler {
    Box::new(move |request, context| {
        // Resolve upstream middleware chain into a response...
        let mut response = handler(request, context);
        // ...mutate response as desired.
        Ok(response)
    })
}

Middleware are wrapped around handlers, which themselves produce a handler for chainable invocation:

use vicuna::{
    default_handler,
    lambda_http::lambda,
    middleware::{body, header},
    Handler,
    WrappingHandler,
};

fn main() {
    lambda!(default_handler()
        .wrap_with(body("Hello, world!"))
        .wrap_with(header("x-foo", "bar"))
        .handler())
}
Commit count: 31

cargo fmt