pub struct Action {
pub name: String,
pub method: Method,
pub path: String,
pub audience: Audience,
pub input: Option<Schema>,
pub outcome: Outcome,
pub policy: RoutePolicy,
pub captcha: bool,
}Expand description
One route the module serves, described for a renderer.
Fields§
§name: StringKebab-case, unique within the module (join, confirm,
export-csv).
method: MethodHTTP method, serialized as its upper-case name.
path: StringPath relative to /v1/<module>, always starting with /.
audience: Audience§input: Option<Schema>JSON Schema of the request body (or of the query for a GET).
None for an action that takes nothing.
outcome: Outcome§policy: RoutePolicyThe explicit protection this route demands (issue #133). Kept in
sync with captcha by the builders and asserted
consistent by Surface::validate: true ⟺ HumanForm.
Deliberately not serialized: the surface document’s wire shape is
unchanged (captcha carries the human-route signal; machine
routes never reach the public subset), so existing consumers and
the compatibility-doc example are unaffected.
captcha: boolWhether the module verifies a captcha token on this action and the
renderer includes the widget. A legacy mirror of policy == HumanForm — the surface JSON keeps the captcha key for existing
consumers; new code declares a policy.
Implementations§
Source§impl Action
impl Action
Sourcepub fn post(name: impl Into<String>, path: impl Into<String>) -> Self
pub fn post(name: impl Into<String>, path: impl Into<String>) -> Self
A public POST that answers 202, the common case for a signup
form. Add .input::<Body>(), .captcha() and friends.
Sourcepub fn get(name: impl Into<String>, path: impl Into<String>) -> Self
pub fn get(name: impl Into<String>, path: impl Into<String>) -> Self
A GET. Audience defaults to Link because a module’s GETs are
the signed-link landings; call .audience(..) otherwise.
Sourcepub fn delete(name: impl Into<String>, path: impl Into<String>) -> Self
pub fn delete(name: impl Into<String>, path: impl Into<String>) -> Self
A DELETE, admin by default.
pub fn new( name: impl Into<String>, method: Method, path: impl Into<String>, ) -> Self
pub fn audience(self, audience: Audience) -> Self
Sourcepub fn input<T: JsonSchema>(self) -> Self
pub fn input<T: JsonSchema>(self) -> Self
Derives the input schema from the handler’s own body type.
Sourcepub fn input_schema(self, schema: Schema) -> Self
pub fn input_schema(self, schema: Schema) -> Self
Supplies a schema built by hand or adjusted after derivation (a
select whose options come from runtime settings).
pub fn outcome(self, outcome: Outcome) -> Self
Sourcepub fn accepted(self, message: impl Into<String>) -> Self
pub fn accepted(self, message: impl Into<String>) -> Self
Shorthand for .outcome(Outcome::Accepted { message }).
Sourcepub fn policy(self, policy: RoutePolicy) -> Self
pub fn policy(self, policy: RoutePolicy) -> Self
Declares how this route proves its requests are legitimate
(issue #133). A payments webhook is .policy(RoutePolicy::Signature)
— never .captcha(), which would render a widget a machine cannot
fill and let the route be counted as captcha-protected.
Sourcepub fn demands_captcha(&self) -> bool
pub fn demands_captcha(&self) -> bool
Whether this route needs the human-form gate: the declared
HumanForm policy, or the legacy captcha: true mirror on an
otherwise-Open route. The one place that alias is resolved, so
the WriteGuards audit, the sidecar merge (issue #131) and the
UI dispatch all check the same predicate.