pub struct Action {
pub class: Option<Vec<String>>,
pub fields: Option<Vec<Field>>,
pub name: String,
pub href: String,
pub method: Option<Method>,
pub title: Option<String>,
pub typ: Option<String>,
}
Expand description
Actions show available behaviors an entity exposes.
Fields
class: Option<Vec<String>>
Describes the nature of an action based on the current representation. Possible values are implementation-dependent and should be documented.
fields: Option<Vec<Field>>
A collection of fields, expressed as an array of objects in JSON Siren such as { "fields" : [{ ... }] }
.
name: String
A string that identifies the action to be performed. Action names MUST be unique within the set of actions for an entity. The behavior of clients when parsing a Siren document that violates this constraint is undefined.
href: String
The URI of the action.
method: Option<Method>
An enumerated attribute mapping to a protocol method.
For HTTP, these values may be GET
, PUT
, POST
, DELETE
, or PATCH
.
As new methods are introduced, this list can be extended.
If this attribute is omitted, GET
should be assumed.
title: Option<String>
Descriptive text about the action.
typ: Option<String>
The encoding type for the request.
When omitted and the fields attribute exists, the default value is application/x-www-form-urlencoded
.
Implementations
sourceimpl Action
impl Action
sourcepub fn builder(name: impl Into<String>, href: impl Into<String>) -> ActionBuilder
pub fn builder(name: impl Into<String>, href: impl Into<String>) -> ActionBuilder
Create a Action builder with the given name and href.
Examples
let action = Action::builder("add-item", "http://api.x.io/orders/42/items");
sourcepub fn classes(&self) -> &Option<Vec<String>>
pub fn classes(&self) -> &Option<Vec<String>>
Returns a reference to the Action’s Classes.
Examples
let action: Action = Action::builder("add-item", "http://api.x.io/orders/42/items")
.classes(vec!["item"]).into();
assert_eq!(&Some(vec!["item".to_string()]), action.classes());
sourcepub fn fields(&self) -> &Option<Vec<Field>>
pub fn fields(&self) -> &Option<Vec<Field>>
Returns a reference to the Action’s Fields.
Examples
let action: Action = Action::builder("add-item", "http://api.x.io/orders/42/items")
.fields(vec![
Field::builder("orderNumber").typ("hidden").value("42"),
Field::builder("productCode").typ("text"),
Field::builder("quantity").typ("number"),
]).into();
assert_eq!(
&Some(vec![
Field::builder("orderNumber").typ("hidden").value("42").into(),
Field::builder("productCode").typ("text").into(),
Field::builder("quantity").typ("number").into(),
]),
action.fields(),
);
sourcepub fn method(&self) -> &Option<Method>
pub fn method(&self) -> &Option<Method>
Returns a reference to the Action’s Method.
Examples
let action: Action = Action::builder("add-item", "http://api.x.io/orders/42/items")
.method(Method::Post).into();
assert_eq!(&Some(Method::Post), action.method());
sourcepub fn title(&self) -> &Option<String>
pub fn title(&self) -> &Option<String>
Returns a reference to the Action’s title.
Examples
let action: Action = Action::builder("add-item", "http://api.x.io/orders/42/items")
.title("Add Item").into();
assert_eq!(&Some("Add Item".to_string()), action.title());
sourcepub fn typ(&self) -> &Option<String>
pub fn typ(&self) -> &Option<String>
Returns a reference to the Action’s type.
Examples
let action: Action = Action::builder("add-item", "http://api.x.io/orders/42/items")
.typ("application/x-www-form-urlencoded").into();
assert_eq!(&Some("application/x-www-form-urlencoded".to_string()), action.typ());