| Crates.io | brk_server |
| lib.rs | brk_server |
| version | 0.0.109 |
| created_at | 2025-02-23 23:35:39.771466+00 |
| updated_at | 2025-09-20 17:22:28.972418+00 |
| description | A server with an API for anything from BRK |
| homepage | https://bitcoinresearchkit.org |
| repository | https://github.com/bitcoinresearchkit/brk |
| max_upload_size | |
| id | 1566729 |
| size | 130,958 |
HTTP server providing REST API access to Bitcoin analytics data
This crate provides a high-performance HTTP server built on axum that exposes Bitcoin blockchain analytics data through a comprehensive REST API. It integrates with the entire BRK ecosystem, serving data from indexers, computers, and parsers with intelligent caching, compression, and multiple output formats.
Key Features:
Target Use Cases:
cargo add brk_server
use brk_server::Server;
use brk_interface::Interface;
use std::path::PathBuf;
// Initialize interface with your data sources
let interface = Interface::new(/* your config */);
// Optional static file serving directory
let files_path = Some(PathBuf::from("./web"));
// Create and start server
let server = Server::new(interface, files_path);
// Start server with optional MCP (Model Context Protocol) support
server.serve(true).await?;
Blockchain Queries:
GET /api/address/{address} - Address information, balance, transaction countsGET /api/tx/{txid} - Transaction details including version, locktimeGET /api/vecs/{variant} - Vector database queries with filteringSystem Information:
GET /api/vecs/index-count - Total number of indexes availableGET /api/vecs/id-count - Vector ID statisticsGET /api/vecs/indexes - List of available data indexesGET /health - Service health statusGET /version - Server version informationQuery Interface:
GET /api/vecs/query - Generic vector query with parametersGET /api/vecs/{variant}?from={start}&to={end}&format={format} - Range queriesSupported Parameters:
from / to: Range filtering (height, timestamp, date-based)format: Output format (json, csv){
"address": "1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2",
"type": "p2pkh",
"index": 12345,
"chain_stats": {
"funded_txo_sum": 500000000,
"spent_txo_sum": 400000000,
"utxo_count": 5,
"balance": 100000000,
"balance_usd": 4200.5,
"realized_value": 450000000,
"avg_cost_basis": 45000.0
}
}
use brk_server::Server;
use brk_interface::Interface;
// Initialize with BRK interface
let interface = Interface::builder()
.with_indexer_path("./data/indexer")
.with_computer_path("./data/computer")
.build()?;
let server = Server::new(interface, None);
// Server automatically finds available port starting from 3110
server.serve(false).await?;
# Get address information
curl http://localhost:3110/api/address/1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2
# Response includes balance, transaction counts, USD value
{
"address": "1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2",
"type": "p2pkh",
"chain_stats": {
"balance": 100000000,
"balance_usd": 4200.50,
"utxo_count": 5
}
}
# Export height-to-price data as CSV
curl "http://localhost:3110/api/vecs/height-to-price?from=800000&to=800100&format=csv" \
-H "Accept-Encoding: gzip"
# Query with caching - subsequent requests return 304 Not Modified
curl "http://localhost:3110/api/vecs/dateindex-to-price-ohlc?from=0&to=1000" \
-H "If-None-Match: \"etag-hash\""
# Get transaction information
curl http://localhost:3110/api/tx/abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890
# Response includes version, locktime, and internal indexing
{
"txid": "abcdef...",
"index": 98765,
"version": 2,
"locktime": 0
}
axum with async/await for high concurrencyquick_cache with LRU eviction and ETag validationThe server implements intelligent caching:
must-revalidate headers for data consistencyOptional static file serving supports:
The server automatically configures itself but respects:
Main Components: Server struct with AppState containing interface, cache, and file paths
HTTP Framework: Built on axum with middleware for compression, tracing, and CORS
API Routes: Address lookup, transaction details, vector queries, and system information
Caching Layer: quick_cache integration with ETag-based conditional requests
Data Integration: Direct interface to BRK indexer, computer, parser, and fetcher components
Static Serving: Optional file serving for web interfaces and documentation
Architecture: Async HTTP server with intelligent caching and multi-format data export capabilities
This README was generated by Claude Code