action
ModuleActions: what an endpoint, task or worker does, described once.
Contents
Structs
ActionWhat an endpoint, a task or a worker job does: its params, injections, labels and callback, and for HTTP its methods, path and aliases. `crate::Platform` registers it on the server of its service.ActionTypeWhat an action is registered as on its server: the work itself (`ActionType::DEFAULT`: a route, a task or a job) or one of the hooks around it. Any other name registers like the default.EnumEnum metadata for a whitelist-backed param, for SDK generators.ParamA param an action declares, forwarded to the hook it registers as.use utopia_platform::Action;Rust
pub struct ActionWhat an endpoint, a task or a worker job does: its params, injections,
labels and callback, and for HTTP its methods, path and aliases.
crate::Platform registers it on the server of its service.
Rust
use serde_json::json;
use utopia_platform::{Action, Param, HTTP_REQUEST_METHOD_POST};
use utopia_validators::Text;
let mut action = Action::new();
action
.set_http_method(HTTP_REQUEST_METHOD_POST)
.set_http_path("/v1/teams")
.desc("Create team")
.groups(&["api", "teams"])
.label("scope", json!("teams.write"))
.param("name", Param::new(json!(""), Text::new(128), "Team name."))
.inject("response");
assert_eq!(action.http_methods(), ["POST"]);
assert_eq!(action.http_path(), Some("/v1/teams"));
assert_eq!(action.injections(), ["response"]);
assert_eq!(action.labels()["scope"], json!("teams.write"));Also implements
Default.use utopia_platform::ActionType;Rust
pub struct ActionType(Cow<'static, str>)What an action is registered as on its server: the work itself
([ActionType::DEFAULT]: a route, a task or a job) or one of the hooks
around it. Any other name registers like the default.
use utopia_platform::Enum;Rust
pub struct EnumEnum metadata for a whitelist-backed param, for SDK generators.
Rust
use utopia_platform::Enum;
let status = Enum::new().name("ArticleStatus").map(&[("draft", "Draft"), ("published", "Published")]);
assert_eq!(status.name.as_deref(), Some("ArticleStatus"));
assert_eq!(status.map.as_ref().map(|m| m["draft"].as_str()), Some("Draft"));use utopia_platform::Param;Rust
pub struct ParamA param an action declares, forwarded to the hook it registers as.
use utopia_platform::Callback;Rust
pub enum CallbackAn action's callback, for the server its service runs on.
Also implements
Debug.use utopia_platform::Declaration;Rust
pub enum DeclarationOne declaration of an action, in order: a param or an injection.
Rust
pub const HTTP_REQUEST_METHOD_DELETE: &str = "DELETE"DELETE.
Rust
pub const HTTP_REQUEST_METHOD_GET: &str = "GET"GET.
Rust
pub const HTTP_REQUEST_METHOD_HEAD: &str = "HEAD"HEAD.
Rust
pub const HTTP_REQUEST_METHOD_OPTIONS: &str = "OPTIONS"OPTIONS.
Rust
pub const HTTP_REQUEST_METHOD_PATCH: &str = "PATCH"PATCH.
Rust
pub const HTTP_REQUEST_METHOD_POST: &str = "POST"POST.
Rust
pub const HTTP_REQUEST_METHOD_PUT: &str = "PUT"PUT.