Crate rjapi

Crate rjapi 

Source
Expand description

JSON:API 1.1 Implementation for Rust

This crate provides a framework-agnostic implementation of the JSON:API 1.1 specification. It includes data structures for JSON:API documents, resources, errors, and helper functions for creating compliant responses.

§Features

  • Fully compliant with JSON:API 1.1 specification
  • Framework-agnostic design (works with Axum, Actix, Rocket, etc.)
  • Support for resources, relationships, errors, and metadata
  • Query parameter support for filtering, sorting, pagination, etc.
  • Extensible and customizable

§Usage

use rjapi::{JsonApiResponse, Resource};
use serde_json::json;

let attributes = json!({
    "title": "Example Post",
    "content": "This is an example post."
});

let resource = Resource {
    resource_type: "posts".to_string(),
    id: "1".to_string(),
    attributes: Some(attributes),
    relationships: None,
    links: None,
    meta: None,
};

// Create a JSON:API response
let response = JsonApiResponse::new(resource).build();
println!("{}", serde_json::to_string_pretty(&response).unwrap());

Re-exports§

pub use http;
pub use error::*;
pub use middleware::*;
pub use response::*;

Modules§

error
JSON:API Error Handling
middleware
JSON:API Middleware Utilities
request
JSON:API Request Handling
response
JSON:API Response Handling