platform
ModuleThe platform: modules registered on the HTTP, CLI and worker servers.
Contents
use utopia_platform::JobConfig;Rust
pub struct JobConfigHow one worker queue is consumed.
use utopia_platform::Platform;Rust
pub struct PlatformAn application made of modules: Platform::init registers the actions
of every module's services of one type on that type's server.
The core module (given to Platform::new) comes first; services added
to the platform go to it.
Rust
use utopia_http::{Http, Request, Response};
use utopia_platform::{Action, Callback, Init, Module, Platform, Service, ServiceType};
let mut root = Action::new();
root.set_http_method("GET").set_http_path("/").inject("response").callback(Callback::Http(utopia_http::action(|scope| {
Box::pin(async move {
scope.response.send(b"Hello World!");
Ok(())
})
})));
let mut service = Service::new(ServiceType::HTTP);
service.add_action("root", root);
let mut platform = Platform::new(Module::new());
platform.add_service("web", service);
platform.init(Init::Http)?;
let http = platform.http();
let request = Request::new("GET", "/", std::iter::empty::<(&str, &str)>(), utopia_http::Bytes::new());
let mut response = Response::new();
http.run(&request, &mut response, &http.context()).await?;
assert_eq!(response.wire().body, b"Hello World!");Also implements
Debug.use utopia_platform::WorkerParams;Rust
pub struct WorkerParamsWhat Platform::init needs for workers.
Also implements
Debug.use utopia_platform::Init;Rust
pub enum InitWhat to initialize: the server type and its settings.