Expand description
§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 :
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. SeeHttpRequestandHttpResponsefor 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());
}
};
}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.
Re-exports§
pub use fetch::HttpFetch;pub use request::HttpMethod;pub use request::HttpRequest;pub use response::HttpResponse;pub use stream::BaseStream;pub use stream::ReadStream;pub use stream::WriteStream;
Modules§
- error
- Error handling enums and utilities.
- fetch
- APIs for executing HTTP requests.
- kv
- APIs for interacting with EDJX KV-Store.
- request
- Read-only HTTP request input for HTTP-trigger serverless functions.
- response
- APIs used to send HTTP Responses for HTTP-triggered serverless functions.
- storage
- APIs for interacting with the EDJX Object Store.
- stream
- APIs for manipulating data streams.
Macros§
- debug
- Logs a message at the debug level.
- error
- Logs a message at the error level.
- fatal
- Logs a message at the fatal level.
- info
- Logs a message at the info level.
- trace
- Logs a message at the trace level.
- warn
- Logs a message at the warn level.
Structs§
- Fetch
Response - Response for HTTP fetch request, which may include body, headers, and status code.
- Fetch
Response Pending FetchResponsePendingis a placeholder for the HTTP server’s response. It is returned whencrate::fetch::HttpFetch::send_streamingis called. It is then used to retriveFetchResponsefrom the server.- File
Attributes - Represents the attributes associated with a stored file.
- Header
Map - A set of HTTP headers
- Header
Name - Represents an HTTP header field name
- Header
Value - Represents an HTTP header field value.
- Method
- The Request Method (VERB)
- Status
Code - An HTTP status code (
status-codein RFC 7230 et al.). - Storage
Response - Response to the
crate::storage::getrequest. - Storage
Response Pending StorageResponsePendingis a placeholder for the EDJX Object Store’s response. It is returned whencrate::storage::put_streamingis called. It is used to retrive aStorageResponseonce it is ready.- Uri
- The URI component of a request.
Enums§
- LogLevel
- An enum representing the available verbosity levels of the logger.