virto-network / valor

Create HTTP APIs with a plugin system that runs in the server and the browser.
GNU General Public License v3.0
9 stars 8 forks source link

Common interfacing for Valor modules #51

Open pandres95 opened 1 year ago

pandres95 commented 1 year ago

Valor: A Multi-Target, Transport-Agnostic Runtime for Modular Code Execution

Valor is a Rust runtime designed to run arbitrary code organized in a modular way, independent of the transport layer. It can be compiled for multiple targets, including server-side applications, WebAssembly (WASM/WASI), and embedded systems.

Design

Module Registry

Valor maintains a static, thread-safe registry of modules. Each module contains a collection of methods, along with arbitrary metadata in the form of extensions. This design allows for organized and manageable execution of code in different environments.

Attribute Macros

Valor provides three attribute macros: valor::module, valor::method, and valor::extensions. These macros are used to define modules and their associated methods and extensions.

Module and Method Structures

Modules and methods in Valor are represented by the Module and Method structs, respectively. Both structs contain a name and a set of extensions. The Method struct also contains a function that can be called to execute the method.

Example Usage

Here's an example of how to define a module and its methods using Valor:

#[valor::module(a_module)]
pub mod a_module {
    use valor::structures::{Request, Response};

    #[valor::method(a_method)]
    #[valor::extensions(http_verb = "GET", http_path = "/")]
    pub fn a_method (request: Request) -> Response {
        // Implement the function
    }
}

In this test, we create a Module, add it to the registry, and then verify that it was correctly added.

Future Work

The design of Valor allows for further expansion and adaptation to different use cases. Future plans include additional attribute macros for more granular control over methods, an expanded registry that can manage modules across multiple servers and applications, and potential integrations with different transport layers. Stay tuned for updates!