3 unstable releases

0.2.0 Dec 22, 2022
0.1.1 Nov 8, 2021
0.1.0 Jul 22, 2021

#424 in HTTP client

MIT license

96KB
2K SLoC

rust-client-edjLibrary-stubs

To build Rust client edjLibrary stubs:

cargo build --release
lib file is created in targe/release directory.

##To build serverless functions in Rust. Go to examples directory/app

cargo build --release --target wasm32-unknown-unknown

WASM file is created in target/release directory.

lib.rs:

EDJX Library SDK for Rust

This crate contains the EDJX SDK library for Rust. This SDK is used to develop EDJX serverless functions. In this version, functions are triggered using HTTP only.

Additionally, developers can use the streaming feature while building serverless functions. Streaming optimizes data transfer (upload file/download file) to the EDJX object storage, and HTTP transfers. Using the streaming feature, developers can work with large data sets without allocating huge memory to the functions. Since functions process data as smaller chunks, the use of streaming in functions drastically reduces the response time.

EDJX HTTP Trigger Functions

These functions are triggered from standard HTTP methods. The input for the function is an HTTP Request object (represented by HttpRequest in the EDJX SDK) and the return value must be an HTTP Response object (represented by HttpResponse in the EDJX SDK).

EDJX sample Rust Serverless Application has two Rust files :

  1. lib.rs : This file contains helper code to fetch HTTP Requests and pass the request as input to the serverless function being developed. Additionally, this file has code related to HTTP Response processing. Modify this file only when a mutable reference to the request is required, or the HTTP Response type needs to be changed. See HttpRequest and HttpResponse for more details.
#[no_mangle]
pub fn init() {
    let req = match HttpRequest::from_client() {
        Ok(val) => val,
        Err(e) => {
            error!("{}", e.to_string().as_str());
            HttpResponse::new()
                .set_status(StatusCode::BAD_REQUEST)
               .send()
               .unwrap();
           return;
       }
   };

  let res = crate::serverless_function::serverless(req);
    match res.send() {
        Ok(x) => x,
        Err(e) => {
            error!("{}", e.to_string().as_str());
        }
    };
}
  1. serverless_function.rs : This file contains the code to create a Serverless Function.
pub fn serverless(req: HttpRequest) -> HttpResponse {
    return HttpResponse::from("Success from EDJX".to_string())
}

HttpRequest is read-only, that is, it has only methods to read input HTTP Request.

Both HttpRequest and HttpResponse APIs are similar to standard RUST HTTP interface. The other important HTTP structs like Headers, Method, StatusCode, and Version are similar to standard RUST HTTP interface.

Two other important structures in this crate are HttpFetch and FetchResponse. HttpFetch is used to execute HTTP Requests. FetchResponse is returned as a response to a Fetch Request. Both these types APIs are similar to standrard RUST HTTP interface

HTTP body size limits

Currently, all HTTP APIs have a size limit of 512 MB for the HTTP body.

Interacting with the EDJX Object Store and KV Store

The most important APIs in the EDJX Library SDK are those used to interact with the Object Storage (represented by storage in the EDJX SDK ) and the KV Store (represented by [kv] in the EDJX SDK)

The Object Store is a decentralized datastore backed by the EDJX P2P network. This SDK uses GET and PUT methods for file contents and associated attributes.

The KV Store is a decentralized Key-Value datastore backed by the EDJX P2P network. Key size is limited to 512 bytes and Value is limited to 512 KB.

Logging

This SDK provides generic Rust-compatible logger APIs similar to standard RUST Log.

Dependencies

~2.7–4MB
~102K SLoC