srvrls

Crates.iosrvrls
lib.rssrvrls
version0.1.7
sourcesrc
created_at2020-04-05 01:56:30.735061
updated_at2020-04-10 14:50:40.681001
descriptionA lightweight, opinionated serverless framework reducing boilerplate
homepage
repositoryhttps://github.com/serverlesstechnology/srvrls
max_upload_size
id226468
size49,113
Serverless Technology (serverlesstechnology)

documentation

README

srvrls

A lightweight wrapper for using AWS Lambda as an API Gateway proxy.

CodeBuild test indicator Crates.io docs


Installation

Srvrls is available from Crates.io or Github.

[dependencies]
srvrls = "0.1.7"

Or for a specific branch

[dependencies]
srvrls = { git = "https://github.com/serverlesstechnology/srvrls.git", branch = "master"}

srvrls

We built this library to simplify building applications that use AWS API Gateway as a proxy for AWS Lambda.

This library has opinions, strong ones, very possibly not your own. Our design priorities here are simple:

  • reduce needed boilerplate in serverless applications
  • provide opinionated defaults to otherwise open questions
  • provide decoupling between the serverless function provider and the application logic (keeping open the option of supporting Google or Azure functions in the future)

In short this wrapper turns this

impl Handler<ApiGatewayProxyRequest, ApiGatewayProxyResponse, HandlerError> for App {
    fn run(&mut self, event: ApiGatewayProxyRequest, _ctx: Context) -> Result<ApiGatewayProxyResponse, HandlerError> {
        match some_function(event) {
            Ok(response) => {
                ApiGatewayProxyResponse {
                    status_code: 200,
                    headers: hashmap!(String::from("Content-Type") => String::from("application/json")),
                    multi_value_headers: HashMap::new(),
                    body: Some(response),
                    is_base64_encoded: None,
                }
            }, 
            Err(e) => {
                ApiGatewayProxyResponse {
                    status_code: 400,
                    headers: hashmap!(String::from("Content-Type") => String::from("application/json")),
                    multi_value_headers: HashMap::new(),
                    body: Some(e.message),
                    is_base64_encoded: None,
                }
            }
        }
    }
}

into this

impl SrvrlsApplication for App {
    fn handle(&mut self, event: SrvrlsRequest) -> Result<SrvrlsResponse, SrvrlsError> {
        let response = some_function(event)?;
        Ok(SrvrlsResponse::ok(response))
    }
}
Commit count: 30

cargo fmt