| Crates.io | spikard-http |
| lib.rs | spikard-http |
| version | 0.9.2 |
| created_at | 2025-11-23 13:05:51.949829+00 |
| updated_at | 2026-01-22 13:15:45.296845+00 |
| description | High-performance HTTP server for Spikard with tower-http middleware stack |
| homepage | https://github.com/Goldziher/spikard |
| repository | https://github.com/Goldziher/spikard |
| max_upload_size | |
| id | 1946517 |
| size | 1,799,285 |
High-performance HTTP server for Spikard with a complete tower-http middleware stack, JSON Schema validation, and cross-language handler execution.
router - Translates route metadata into strongly typed Rust handlers with path extractionvalidation - Enforces JSON schemas for headers, cookies, query params, and request bodiesserver - Wraps Axum/Tokio bootstrapping and exposes configuration via ServerConfighandler - Language-agnostic Handler trait for FFI integrationmiddleware - Tower middleware stack with sensible defaultsNative Rust implementation using Axum and tower-http middleware. Benchmarks on macOS (Darwin 24.6.0) with 50 concurrent connections:
| Workload | Throughput | Mean Latency | P95 Latency | P99 Latency | Memory |
|---|---|---|---|---|---|
| Baseline | 165,228 req/s | 0.30ms | 0.36ms | 0.45ms | 17.4 MB |
| JSON Bodies | pending | pending | pending | pending | pending |
| Multipart Forms | pending | pending | pending | pending | pending |
| URL-Encoded | pending | pending | pending | pending | pending |
Architecture Highlights:
Pin<Box<dyn Future>> enables language-agnostic integrationThe native Rust implementation provides ~38% higher throughput compared to Python bindings while maintaining even lower latency characteristics. Startup time averages 1.01s with first response in 908ms.
Full benchmark methodology: tools/benchmark-harness/
[dependencies]
spikard-http = "0.9.2"
tokio = { version = "1", features = ["full"] }
axum = "0.8"
[dependencies]
spikard-http = { version = "0.9.2", features = ["di"] }
di - Enables dependency injection supportuse spikard_http::{ServerConfig, start_server};
use spikard_core::{RouteConfig, Request, Response};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = ServerConfig {
host: "0.0.0.0".to_string(),
port: 8080,
..Default::default()
};
// Create routes with schemas
let routes = vec![
RouteConfig::get("/health")
.handler("health", |_req| async {
Ok(Response::new(200).with_body(r#"{"status": "ok"}"#))
}),
];
start_server(config, routes).await?;
Ok(())
}
The default middleware stack (in order):
See ServerConfig documentation for detailed configuration options.
Validate requests against JSON schemas:
use spikard_http::validation::ValidateRequest;
use serde_json::json;
let schema = json!({
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "integer", "minimum": 0 }
},
"required": ["name"]
});
request.validate_body(&schema)?;
cargo build -p spikard-http or task build:httpcargo test -p spikard-httptools/benchmark-harness/MIT