5 releases
Uses new Rust 2024
| new 0.1.4 | Jan 29, 2026 |
|---|---|
| 0.1.3 | Jan 21, 2026 |
| 0.1.2 | Jan 16, 2026 |
| 0.1.1 | Jan 10, 2026 |
| 0.1.0 | Jan 5, 2026 |
#650 in HTTP server
Used in legalis
11MB
248K
SLoC
legalis-api
REST API server for Legalis-RS.
Overview
legalis-api provides a production-ready REST API server built with Axum for managing and evaluating legal statutes programmatically.
Features
- REST API: Full CRUD operations for statutes
- Verification Endpoints: Validate statute consistency
- Evaluation Endpoints: Check eligibility for entities
- Health Checks: Kubernetes-ready health endpoints
- OpenAPI Compatible: Standard REST conventions
Endpoints
Statutes
| Method | Path | Description |
|---|---|---|
GET |
/api/v1/statutes |
List all statutes |
GET |
/api/v1/statutes/:id |
Get statute by ID |
POST |
/api/v1/statutes |
Create new statute |
PUT |
/api/v1/statutes/:id |
Update statute |
DELETE |
/api/v1/statutes/:id |
Delete statute |
Verification
| Method | Path | Description |
|---|---|---|
POST |
/api/v1/verify |
Verify statute(s) |
POST |
/api/v1/verify/:id |
Verify specific statute |
Evaluation
| Method | Path | Description |
|---|---|---|
POST |
/api/v1/evaluate |
Evaluate entity against statutes |
POST |
/api/v1/evaluate/:id |
Evaluate against specific statute |
Health
| Method | Path | Description |
|---|---|---|
GET |
/health |
Health check |
GET |
/ready |
Readiness check |
Usage
As Library
use legalis_api::{create_router, AppState};
use std::sync::Arc;
#[tokio::main]
async fn main() {
let state = Arc::new(AppState::new());
let app = create_router(state);
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
Via CLI
# Start API server
legalis serve --host 0.0.0.0 --port 3000
API Examples
# Create a statute
curl -X POST http://localhost:3000/api/v1/statutes \
-H "Content-Type: application/json" \
-d '{"id": "adult-rights", "title": "Adult Rights", ...}'
# Verify all statutes
curl -X POST http://localhost:3000/api/v1/verify
# Evaluate an entity
curl -X POST http://localhost:3000/api/v1/evaluate \
-H "Content-Type: application/json" \
-d '{"entity": {"age": 25, "income": 50000}}'
Configuration
| Environment Variable | Default | Description |
|---|---|---|
HOST |
127.0.0.1 |
Server bind address |
PORT |
3000 |
Server port |
LOG_LEVEL |
info |
Logging level |
Cargo Features
The following features are available:
- grpc (enabled by default): gRPC API server with reflection and health checking
- redis-cache: Redis-based caching support for improved performance
- oauth2-auth: OAuth2 authentication and authorization
- otel-tracing: OpenTelemetry tracing integration for observability
Default Build (Includes gRPC)
cargo build
Minimal Build (No gRPC)
If you don't need the gRPC API and want to reduce dependencies:
[dependencies]
legalis-api = { version = "0.1", default-features = false }
Or build with:
cargo build --no-default-features
Custom Feature Combination
[dependencies]
legalis-api = { version = "0.1", default-features = false, features = ["redis-cache", "oauth2-auth"] }
License
MIT OR Apache-2.0
Dependencies
~131MB
~2M SLoC