SentryStr API
REST API server for the SentryStr ecosystem, providing HTTP endpoints for querying and serving error events.
Overview
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.
Features
- RESTful API: Clean HTTP endpoints for event querying
- Event Filtering: Query events by author, level, time range, and more
- JSON Responses: Structured JSON responses for easy integration
- CORS Support: Cross-origin resource sharing for web applications
- Health Checks: Built-in health check endpoint
- Async Performance: Built on Axum for high-performance async handling
Quick Start
Add this to your Cargo.toml:
[]
= "0.1.0"
Basic server setup:
use create_app;
async
API Endpoints
GET /health
Health check endpoint that returns the server status.
Response:
Example:
GET /events
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 until
Response:
Examples:
# Get last 10 events
# Get error events only
# Get events from specific author
# Get events from last 24 hours
# Combined filters
GET /events/{author}
Get events from a specific author.
Path Parameters:
author: Author's public key in hex or npub format
Query Parameters:
Same as /events endpoint except author is not needed.
Example:
Configuration
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 to
Integration with SentryStr Collector
The API typically works with the SentryStr Collector to provide event data:
use create_app;
use EventCollector;
async
Docker Support
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"]
Related Crates
- sentrystr: Core library for publishing events
- sentrystr-collector: Event collection from Nostr relays
- sentrystr-tracing: Tracing integration
License
MIT License - see LICENSE file for details.