Module hateoas

Module hateoas 

Source
Expand description

HATEOAS (Hypermedia As The Engine Of Application State) support

This module provides hypermedia link support for REST APIs following the HAL (Hypertext Application Language) specification.

§Overview

HATEOAS enables REST APIs to provide navigation links in responses, making APIs more discoverable and self-documenting.

§Example

use rustapi_core::hateoas::{Resource, Link};

#[derive(Serialize)]
struct User {
    id: i64,
    name: String,
}

async fn get_user(Path(id): Path<i64>) -> Json<Resource<User>> {
    let user = User { id, name: "John".to_string() };
     
    Json(Resource::new(user)
        .self_link(&format!("/users/{}", id))
        .link("orders", &format!("/users/{}/orders", id))
        .link("profile", &format!("/users/{}/profile", id)))
}

Structs§

Link
A hypermedia link following HAL specification
PageInfo
Pagination information
Resource
Resource wrapper with HATEOAS links (HAL format)
ResourceCollection
Collection of resources with pagination support

Enums§

LinkOrArray
Either a single link or an array of links

Traits§

Linkable
Helper trait for adding HATEOAS links to any type