Crates.io | http_siren |
lib.rs | http_siren |
version | 0.1.0 |
source | src |
created_at | 2022-07-23 09:37:31.404999 |
updated_at | 2022-07-23 09:37:31.404999 |
description | Support for Siren responses in HTTP APIs |
homepage | https://github.com/sazzer/http_siren/ |
repository | https://github.com/sazzer/http_siren/ |
max_upload_size | |
id | 631348 |
size | 46,939 |
This crate provides an implementation of the Siren Hypermedia specification.
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
.
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.
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.This crate uses #![forbid(unsafe_code)]
to ensure everything is implemented in 100% safe Rust.
The MSRV for http_siren
is 1.60.0. However, the HTTP Servers that are used with it might need a higher version.
This project is licensed under the MIT license.
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.