docs.rs failed to build kaccy-api-0.1.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
kaccy-api
REST API layer for Kaccy Protocol.
Overview
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.
Modules
routes
API route handlers:
auth- Authentication endpoints (register, login)users- User profile managementtokens- Token CRUD and trading
middleware
HTTP middleware:
auth- JWT authentication and authorization- (Planned) Rate limiting, CORS, logging
state
Application state management:
AppState- Shared state with database pool, JWT secret, Bitcoin client
error
API error handling:
ApiError- Unified error responses with HTTP status codes
API Endpoints
Authentication
| Method | Path | Description |
|---|---|---|
| POST | /api/auth/register |
Register new user |
| POST | /api/auth/login |
Login and get JWT token |
Users (Protected)
| 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 |
Tokens
| 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) |
Health
| Method | Path | Description |
|---|---|---|
| GET | /health |
Health check |
Usage
use AppState;
use create_pool;
async
Configuration
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)
Architecture
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
Dependencies
axum- Web frameworktower- Middleware and service utilitiestower-http- HTTP-specific middleware (CORS, tracing)jsonwebtoken- JWT encoding/decodingargon2- Password hashing
Testing
# Run unit tests
# Integration test with curl