anycms-core
A unified API response library supporting multiple Rust web frameworks.
Features
- Framework-agnostic core:
ApiResult<T>structure works independently of any web framework - Multiple framework support: Built-in integrations for actix-web and axum
- Feature flags: Use only what you need - zero unused dependencies
- Flexible response format: Support for single values, lists, pagination, error codes, and extra metadata
Installation
Add this to your Cargo.toml:
[]
= "0.2"
Feature Flags
actix(default): Enable actix-web integrationaxum: Enable axum integrationfull: Enable all framework integrations
Examples
# Default (actix-web only)
= "0.2"
# Axum only
= { = "0.2", = ["axum"] }
# Both frameworks
= { = "0.2", = ["full"] }
Project Structure
src/
├── lib.rs # Library entry point with feature-gated exports
├── result.rs # Core ApiResult<T> definition (framework-agnostic)
├── pagination.rs # Pagination metadata structure
└── frameworks/
├── mod.rs # Framework module declarations
├── actix.rs # actix-web integration (Responder trait)
└── axum.rs # axum integration (IntoResponse trait)
Architecture
The library is designed with a clear separation of concerns:
-
Core Layer (result.rs, pagination.rs)
- Contains data structures and builder methods
- Zero framework dependencies
- Always compiled regardless of features
-
Framework Layer (frameworks/)
- Implements framework-specific traits
- Conditionally compiled based on feature flags
- Isolated to prevent conflicts
Usage
Actix-web
use ;
use ;
async
Axum
use ;
use ;
async
Examples
Run the demo examples:
# Actix-web demo
# Axum demo
# Check examples
API Response Format
Success Response (Single Value)
Success Response (List)
Error Response
License
MIT