| Crates.io | kaccy-api |
| lib.rs | kaccy-api |
| version | 0.1.0 |
| created_at | 2026-01-18 22:52:39.628315+00 |
| updated_at | 2026-01-18 22:52:39.628315+00 |
| description | REST API and WebSocket server for Kaccy Protocol - comprehensive backend service |
| homepage | https://github.com/cool-japan/kaccy |
| repository | https://github.com/cool-japan/kaccy |
| max_upload_size | |
| id | 2053268 |
| size | 932,858 |
REST API layer for Kaccy Protocol.
This crate provides the HTTP API endpoints using the Axum web framework. It exposes all platform functionality through a RESTful interface with JWT-based authentication.
routesAPI route handlers:
auth - Authentication endpoints (register, login)users - User profile managementtokens - Token CRUD and tradingmiddlewareHTTP middleware:
auth - JWT authentication and authorizationstateApplication state management:
AppState - Shared state with database pool, JWT secret, Bitcoin clienterrorAPI error handling:
ApiError - Unified error responses with HTTP status codes| Method | Path | Description |
|---|---|---|
| POST | /api/auth/register |
Register new user |
| POST | /api/auth/login |
Login and get JWT token |
| Method | Path | Description |
|---|---|---|
| GET | /api/users/me |
Get current user profile |
| PUT | /api/users/me |
Update profile |
| GET | /api/users/:id |
Get user by ID |
| Method | Path | Description |
|---|---|---|
| GET | /api/tokens |
List tokens (with filters) |
| GET | /api/tokens/:id |
Get token details |
| POST | /api/tokens |
Create new token (protected) |
| POST | /api/tokens/:id/buy |
Create buy order (protected) |
| POST | /api/tokens/:id/sell |
Create sell order (protected) |
| Method | Path | Description |
|---|---|---|
| GET | /health |
Health check |
use kaccy_api::state::AppState;
use kaccy_db::create_pool;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let pool = create_pool(&std::env::var("DATABASE_URL")?).await?;
let state = AppState::new(
pool,
std::env::var("JWT_SECRET")?,
);
// Build and run the server
let app = kaccy_api::routes::create_router(state);
let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await?;
axum::serve(listener, app).await?;
Ok(())
}
Environment variables:
DATABASE_URL - PostgreSQL connection stringJWT_SECRET - Secret key for JWT signing (64+ characters)HOST - Server host (default: 0.0.0.0)PORT - Server port (default: 8080)RUST_LOG - Log level (e.g., debug, info)kaccy-api/
├── src/
│ ├── lib.rs # Crate root
│ ├── main.rs # Server entrypoint
│ ├── state.rs # Application state
│ ├── error.rs # Error handling
│ ├── routes/
│ │ ├── mod.rs # Router setup
│ │ ├── auth.rs # Auth endpoints
│ │ ├── users.rs # User endpoints
│ │ └── tokens.rs # Token endpoints
│ └── middleware/
│ ├── mod.rs
│ └── auth.rs # JWT middleware
└── Cargo.toml
axum - Web frameworktower - Middleware and service utilitiestower-http - HTTP-specific middleware (CORS, tracing)jsonwebtoken - JWT encoding/decodingargon2 - Password hashing# Run unit tests
cargo test -p kaccy-api
# Integration test with curl
curl http://localhost:8080/health