pub struct Link {
pub rel: String,
pub href: String,
pub method: Option<String>,
}Expand description
A single HATEOAS link with a relation type, target URL, and optional HTTP method hint.
The rel field follows the
IANA link relations registry
where applicable (e.g. "self", "next", "prev").
Fields§
§rel: StringThe link relation type (e.g. "self", "next", "related").
href: StringThe target URL.
method: Option<String>Optional HTTP method hint (e.g. "GET", "POST").
Implementations§
Source§impl Link
impl Link
Sourcepub fn new(rel: impl Into<String>, href: impl Into<String>) -> Self
pub fn new(rel: impl Into<String>, href: impl Into<String>) -> Self
Create a new Link with the given relation and href.
use api_bones::links::Link;
let link = Link::new("related", "/other");
assert_eq!(link.rel, "related");
assert_eq!(link.href, "/other");
assert!(link.method.is_none());Sourcepub fn method(self, method: impl Into<String>) -> Self
pub fn method(self, method: impl Into<String>) -> Self
Set the optional HTTP method hint (builder-style).
use api_bones::links::Link;
let link = Link::new("create", "/items").method("POST");
assert_eq!(link.method.as_deref(), Some("POST"));Sourcepub fn self_link(href: impl Into<String>) -> Self
pub fn self_link(href: impl Into<String>) -> Self
Construct a "self" link.
use api_bones::links::Link;
let link = Link::self_link("/resources/42");
assert_eq!(link.rel, "self");
assert_eq!(link.href, "/resources/42");Sourcepub fn next(href: impl Into<String>) -> Self
pub fn next(href: impl Into<String>) -> Self
Construct a "next" link (next page in a paginated response).
use api_bones::links::Link;
let link = Link::next("/resources?page=2");
assert_eq!(link.rel, "next");
assert_eq!(link.href, "/resources?page=2");Sourcepub fn prev(href: impl Into<String>) -> Self
pub fn prev(href: impl Into<String>) -> Self
Construct a "prev" link (previous page in a paginated response).
use api_bones::links::Link;
let link = Link::prev("/resources?page=1");
assert_eq!(link.rel, "prev");
assert_eq!(link.href, "/resources?page=1");Construct a "related" link.
use api_bones::links::Link;
let link = Link::related("/users/42");
assert_eq!(link.rel, "related");
assert_eq!(link.href, "/users/42");Trait Implementations§
Source§impl<'de> Deserialize<'de> for Link
impl<'de> Deserialize<'de> for Link
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Link
impl StructuralPartialEq for Link
Auto Trait Implementations§
impl Freeze for Link
impl RefUnwindSafe for Link
impl Send for Link
impl Sync for Link
impl Unpin for Link
impl UnsafeUnpin for Link
impl UnwindSafe for Link
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more