Crate lambda_flows

source ·
Expand description

Make a flow function working as a lambda service in Flows.network

Quick Start

To get started, let’s write a very tiny flow function.

use lambda_flows::{request_received, send_response};

#[no_mangle]
#[tokio::main(flavor = "current_thread")]
pub async fn run() {
    request_received(handler).await;
}

async fn handler(_headers: Vec<(String, String)>, _qry: HashMap<String, Value>, _body: Vec<u8>) {
    send_response(
        200,
        vec![(String::from("content-type"), String::from("text/html"))],
        "ok".as_bytes().to_vec(),
    );
}

When a new request is received the callback closure of function request_received() will be called and send_response() is used to make the response.

Functions

  • Register a callback closure with the query and body of the request for the lambda service.
  • Set the response for the lambda service.