rjapi - JSON:API 1.1 Implementation for Rust
A framework-agnostic, ergonomic, and type-safe implementation of the JSON:API 1.1 specification for Rust applications.
Features
- ✅ Compliant & Modern: Fully compliant with the JSON:API 1.1 specification.
- 🚀 Framework-Agnostic: Designed to work seamlessly with any web framework, including Axum, Actix Web, and Rocket.
- 🛡️ Type-Safe by Design: Leverages Rust's type system to prevent common errors at compile time. Application-specific models are used directly, reducing the need for manual and error-prone conversions.
- ✨ Ergonomic API: A fluent, builder-based API for constructing responses and a powerful extractor for handling requests makes your code cleaner and more readable.
- 📦 Lightweight & Efficient: A minimal dependency footprint and an architecture focused on performance ensure your application remains fast.
- 🔧 Extensible: Easily extendable to fit your application's specific needs.
- 📚 Comprehensive Documentation: Clear and detailed documentation with practical examples.
Installation
Add this to your Cargo.toml:
[]
= "0.0.1"
= { = "1.0", = ["derive"] }
= "1.0"
Usage
Defining a Resource
To make your models compatible with rjapi, implement the JsonApiResource trait.
use JsonApiResource;
use Serialize;
use json;
Creating a Response
Use the JsonApiResponse builder to construct type-safe, compliant JSON:API responses.
use ;
# use JsonApiResource;
# use Serialize;
# use json;
#
#
#
let post = Post ;
let resource = Resource ;
let response = new.build;
println!;
Framework Integration (Axum Example)
The JsonApiRequest extractor simplifies request handling in your web framework.
use ;
use ;
use ;
use Arc;
use RwLock;
// Application state
#
#
#
// A specific type for post creation attributes
// Axum handler for creating a post
async
Documentation
For full documentation, visit docs.rs/rjapi.
Examples
Check out the examples directory for more detailed usage examples:
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please read our Contributing Guide for details on how to submit pull requests, report issues, and suggest improvements.
Changelog
0.0.1 (Initial Release)
- Framework-agnostic JSON:API 1.1 implementation
- Support for resources, relationships, errors, and metadata
- Middleware for content-type validation
- Comprehensive examples and documentation