http_siren

Crates.iohttp_siren
lib.rshttp_siren
version0.1.0
sourcesrc
created_at2022-07-23 09:37:31.404999
updated_at2022-07-23 09:37:31.404999
descriptionSupport for Siren responses in HTTP APIs
homepagehttps://github.com/sazzer/http_siren/
repositoryhttps://github.com/sazzer/http_siren/
max_upload_size
id631348
size46,939
Graham Cox (sazzer)

documentation

README

Problem Details

Build status Crates.io Documentation

This crate provides an implementation of the Siren Hypermedia specification.

Example Usage

The following is a valid handler for Axum that returns a subset of the example from the Siren specification:

async fn example() -> http_siren::Response<OrderProperties> {
    http_siren::Document::new(OrderProperties {
        order_number: 42,
        item_count: 3,
        status: "pending".to_owned(),
    })
    .with_class("order")
    .with_embedded_link(
        http_siren::Link::new("http://api.x.io/orders/42/items")
            .with_class("items")
            .with_class("collection")
            .with_rel("http://x.io/rels/order-items"),
    ).into()
}

#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
struct OrderProperties {
    pub order_number: u32,
    pub item_count: u32,
    pub status: String,
}

When used with a supported HTTP Server, this will automatically generate the correct JSON response and set the Content-Type header to the correct value of application/vnd.siren+json.

Supported HTTP Servers

Currently this is only supported with the following HTTP Servers:

Examples of use with the different HTTP Servers can be found in the examples directory.

Features

HTTP Server support is behind feature flags for the appropriate HTTP Server. As such, you will need to enable the correct feature for the HTTP Server that you are using.

Currently supported features are:

  • axum - For the Axum HTTP Server.

Safety

This crate uses #![forbid(unsafe_code)] to ensure everything is implemented in 100% safe Rust.

Minimum supported Rust version

The MSRV for http_siren is 1.60.0. However, the HTTP Servers that are used with it might need a higher version.

License

This project is licensed under the MIT license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in http_siren by you, shall be licensed as MIT, without any additional terms or conditions.

Commit count: 6

cargo fmt