C++ edjLibrary SDK
EDJX Library SDK for C++

This SDK is used to develop EDJX serverless functions. In this version, only HTTP trigger functions are supported. That is, functions can be triggered using HTTP only.

EDJX HTTP Trigger Functions

These functions are triggered from standard HTTP methods. The input for the function is an HTTP request object (represented by edjx::request::HttpRequest in the EDJX SDK) and the return value has to be an HTTP response object (represented by edjx::response::HttpResponse in the EDJX SDK).

EDJX sample C++ Serverless Application has two C++ files:

  • lib.cpp
  • serverless_function.cpp

lib.cpp

This file contains helper code to fetch HTTP requests and pass the request as input to the serverless function. Additionally, this file has code related to HTTP response processing. Modify this file only when the HTTP body prefetch needs to be disabled for HTTP request, or the HTTP response type needs to be changed. See edjx::request::HttpRequest and edjx::response::HttpResponse for more details.

static const HttpStatusCode HTTP_STATUS_BAD_REQUEST = 400;
extern HttpResponse serverless(const HttpRequest & req);
int main(void) {
HttpRequest req;
HttpError err = HttpRequest::from_client(req, true);
if (err != HttpError::Success) {
HttpResponse().set_status(HTTP_STATUS_BAD_REQUEST).send();
return EXIT_FAILURE;
}
HttpResponse res = serverless(req);
err = res.send();
if (err != HttpError::Success) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
HttpError
Enum describing return values of functions that correspond to HTTP modules.
Definition: error.hpp:14
std::string to_string(HttpError e)
Returns a string representation of HttpError.
Definition: error.hpp:49
uint16_t HttpStatusCode
HTTP status code (e.g., value 200 means OK, value 404 means Not Found)
Definition: http.hpp:60
void error(const std::string &log_str)
Logs a message at the error level.

serverless_function.cpp

This file contains the code to create a Serverless Function.

static const HttpStatusCode HTTP_STATUS_OK = 200;
HttpResponse serverless(const HttpRequest & req) {
info("Inside example function");
return HttpResponse("Welcome to EDJX")
.set_status(HTTP_STATUS_OK)
.set_header("Server", "EDJX");
}
void info(const std::string &log_str)
Logs a message at the info level.

The edjx::request::HttpRequest reference to the argument is read-only, that is, it has only methods to read a received HTTP request.

Two other important types in the API are edjx::fetch::HttpFetch and edjx::fetch::FetchResponse. HttpFetch is used to execute HTTP requests. FetchResponse is returned as a response for the fetch HTTP request.

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 edjx::storage namespace in the EDJX SDK) and the KV Store (represented by edjx::kv namespace in the EDJX SDK).

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

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

Logging

This API provides functions to log std::string messages.