Crates.io | vnd_siren |
lib.rs | vnd_siren |
version | 0.2.1 |
source | src |
created_at | 2018-11-12 06:10:07.323691 |
updated_at | 2018-12-09 05:53:09.679824 |
description | A SIREN DSL/serializer |
homepage | https://gitlab.com/Txuritan/vnd-siren |
repository | https://gitlab.com/Txuritan/vnd-siren |
max_upload_size | |
id | 96193 |
size | 55,180 |
vnd-SIREN is a SIREN DSL/serializer for Rust.
Recreating the sample given on the SIREN repository:
let siren = Entity::builder()
.class("order")
.properties(vec![
Property::new("itemCount", 3),
Property::new("orderNumber", 42),
Property::new("status", "pending"),
])
.actions(vec![
Action::builder("add-item", "http://api.x.io/orders/42/items")
.method(Method::Post)
.title("Add Item")
.typ("application/x-www-form-urlencoded")
.fields(vec![
Field::builder("orderNumber").typ("hidden").value("42"),
Field::builder("productCode").typ("text"),
Field::builder("quantity").typ("number"),
]),
])
.entities(vec![
Entity::builder()
.rel(vec!["http://x.io/rels/order-items"])
.classes(vec!["items", "collection"])
.href("http://api.x.io/orders/42/items"),
Entity::builder()
.rel(vec!["http://x.io/rels/customer"])
.classes(vec!["info", "customer"])
.links(vec![
Link::builder(vec!["self"], "http://api.x.io/customers/pj123"),
])
.properties(vec![
Property::new("customerId", "pj123"),
Property::new("name", "Peter Joseph"),
]),
])
.links(vec![
Link::builder(vec!["self"], "http://api.x.io/orders/42"),
Link::builder(vec!["previous"], "http://api.x.io/orders/41"),
Link::builder(vec!["next"], "http://api.x.io/orders/43"),
]);