| Crates.io | sentrystr-api |
| lib.rs | sentrystr-api |
| version | 0.1.2 |
| created_at | 2025-09-21 21:38:15.996136+00 |
| updated_at | 2025-09-22 21:21:27.477855+00 |
| description | REST API for serving SentryStr events from Nostr network |
| homepage | |
| repository | https://github.com/9qeklajc/sentrystr |
| max_upload_size | |
| id | 1849228 |
| size | 77,031 |
REST API server for the SentryStr ecosystem, providing HTTP endpoints for querying and serving error events.
The SentryStr API provides a REST interface for accessing SentryStr events collected from Nostr relays. It's designed to be used with monitoring dashboards, alerting systems, and other tools that need HTTP access to event data.
Add this to your Cargo.toml:
[dependencies]
sentrystr-api = "0.1.0"
Basic server setup:
use sentrystr_api::create_app;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let app = create_app();
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;
println!("SentryStr API server running on http://localhost:3000");
axum::serve(listener, app).await?;
Ok(())
}
Health check endpoint that returns the server status.
Response:
{
"status": "ok",
"timestamp": "2024-01-01T00:00:00Z"
}
Example:
curl "http://localhost:3000/health"
Query events with optional filters.
Query Parameters:
limit: Maximum number of events to return (default: 50, max: 1000)level: Filter by event level (debug, info, warning, error, fatal)author: Filter by author's public key (hex or npub format)since: ISO 8601 timestamp to filter events sinceuntil: ISO 8601 timestamp to filter events untilResponse:
{
"events": [
{
"id": "event-uuid",
"message": "Error message",
"level": "error",
"timestamp": "2024-01-01T00:00:00Z",
"author": "npub1...",
"fields": {
"custom_field": "value"
}
}
],
"count": 1,
"has_more": false
}
Examples:
# Get last 10 events
curl "http://localhost:3000/events?limit=10"
# Get error events only
curl "http://localhost:3000/events?level=error"
# Get events from specific author
curl "http://localhost:3000/events?author=npub1..."
# Get events from last 24 hours
curl "http://localhost:3000/events?since=2024-01-01T00:00:00Z"
# Combined filters
curl "http://localhost:3000/events?level=error&limit=50&since=2024-01-01T00:00:00Z"
Get events from a specific author.
Path Parameters:
author: Author's public key in hex or npub formatQuery Parameters:
Same as /events endpoint except author is not needed.
Example:
curl "http://localhost:3000/events/npub1.../events?limit=20"
The API server can be configured with environment variables:
SENTRYSTR_API_PORT: Server port (default: 3000)SENTRYSTR_API_HOST: Server host (default: 0.0.0.0)SENTRYSTR_RELAYS: Comma-separated list of Nostr relays to connect toThe API typically works with the SentryStr Collector to provide event data:
use sentrystr_api::create_app;
use sentrystr_collector::EventCollector;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Start background event collection
let relays = vec!["wss://relay.damus.io".to_string()];
let collector = EventCollector::new(relays).await?;
// Start background collection task
tokio::spawn(async move {
// Collection logic here
});
// Start API server
let app = create_app();
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;
println!("SentryStr API server running on http://localhost:3000");
axum::serve(listener, app).await?;
Ok(())
}
A Dockerfile is provided for containerized deployment:
FROM rust:1.70 as builder
WORKDIR /app
COPY . .
RUN cargo build --release --bin sentrystr-api
FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/target/release/sentrystr-api /usr/local/bin/sentrystr-api
EXPOSE 3000
CMD ["sentrystr-api"]
MIT License - see LICENSE file for details.