Skip to main content

Crate phrona_api

Crate phrona_api 

Source
Expand description

§Phrona API

The server surface for Phrona: a REST API plus an MCP-over-TCP endpoint, with rate limiting, API-key auth and a bundled web console.

Build the router with router and serve it with axum, or run the whole thing with the phrona serve CLI.

Modules§

frontend
Serves the static web frontend.
grounding
AI grounding endpoint: extractive answers over ranked search results.
metrics
Prometheus metrics for the REST API.
tavily
Tavily-compatible /search endpoint.
tools
Page extraction and engine-test endpoints.

Structs§

AppError
An API error with a JSON-friendly representation: bad request, unauthorized, rate limited, body too large, or an internal phrona failure.
AppState
Shared server state: the search client, rate limiter, API key and per-request bounds. Construct with AppState::new.
HeaderAuth
Header-only auth for GET endpoints. Query-string api_key parameters are rejected with a 400: credentials in URLs leak through logs, proxies and referrers and are a classic SSRF/credential-theft vector.
JsonBody
JSON body extractor whose rejection (missing body, malformed JSON, wrong content type) is a JSON 400 instead of axum’s defaults. Bodies larger than the configured server.max_body_bytes are rejected with a 413 before deserialization.
JsonQuery
Query-string extractor whose rejection is a JSON 400 instead of axum’s default plain-text response.

Functions§

router
Build the axum router from a PhronaConfig: the search client (profile / timeout / proxies / concurrency), the API key, the max_results clamp, the rate limit and the body-size cap all come from the config.
serve
Serve the REST API on addr. Blocks until the server stops (Ctrl+C or SIGTERM trigger a graceful shutdown that drains in-flight requests).
shutdown_signal
Wait for Ctrl+C or SIGTERM, then return so the server can drain in-flight requests gracefully.