Protobuf beside JSON in ipx's, the directory's and ipx-play's APIs (#465); ipx's build touches crates/play (#466)

A client sending Accept: application/x-protobuf gets protobuf, and one
sending Content-Type: application/x-protobuf may send its body so; JSON
stays the default, so the page, the TUI and older iOS builds see nothing
new. ipx's own calls to the directory and ipx-play now go in protobuf.

The handlers are untouched. A new crate, ipx-wire, holds the .proto
files (compiled by protox in build.rs, so no protoc anywhere) and one
layer, negotiate, that converts JSON at the edge through prost-reflect,
by a table of each route's messages. Writing prost structs beside every
serde one would have doubled each type and every handler.

Protobuf cannot tell absent from empty or from null, and the PATCH
bodies depend on that: an Option<Vec> left out leaves the list, an empty
one clears it, and null clears a folder. So a list in a body is a
one-field message (absent or present), and null-to-clear is a
google.protobuf.Value. Numbers in a Value come back whole, or 3.0 would
not read as a usize.

Debug builds convert every JSON answer strictly and answer 500 for a
field missing from the .proto or a route missing from a table; the cargo
tests and the browser suite (125 tests) ran clean that way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 22:23:06 +00:00
parent 2671d13489
commit c0998f1ac7
26 changed files with 1282 additions and 30 deletions

View File

@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- `/v1` answers in protobuf for a client that asks for it (`Accept: application/x-protobuf`) and takes a snapshot sent so; JSON stays the default. The messages are in `crates/wire/proto/directory.proto` (#465).
- A `robots.txt` and a sitemap listing the home page, A to Z, every category and every feed, so search engines find the pages, not only the links between them (#380).
- `/metrics` counts its requests and their times by route and status, the feeds it checks and those that failed, and the snapshots it takes (#370).
- Its log lines inside a trace carry the trace's and span's ids, as ipx's do, so a failed feed check leads to its trace (#375).

View File

@@ -18,6 +18,7 @@ axum.workspace = true
clap.workspace = true
futures-util.workspace = true
ipx-feed.workspace = true
ipx-wire.workspace = true
opentelemetry.workspace = true
opentelemetry-otlp.workspace = true
opentelemetry_sdk.workspace = true

View File

@@ -17,6 +17,18 @@ use tower_http::compression::CompressionLayer;
use tower_http::decompression::RequestDecompressionLayer;
use tracing::Instrument;
/// Each route's protobuf messages (#465), beside its JSON.
const WIRE: ipx_wire::Routes = &[
("GET", "/v1/me", "", "directory.Me"),
("GET", "/v1/feeds", "", "directory.Listings"),
("GET", "/v1/popular", "", "directory.Listings"),
("GET", "/v1/feeds/{id}", "", "directory.FeedPage"),
("POST", "/v1/feeds/{id}/refresh", "", "directory.FeedPage"),
("POST", "/v1/snapshot", "directory.Snapshot", "directory.SnapshotResult"),
("GET", "/v1/blocked", "", "directory.BlockedList"),
("GET", "/v1/instances", "", "directory.Instances"),
];
/// Every route: the API under `/v1`, behind a token, and the public pages.
pub fn router(dir: Shared) -> Router {
let v1 = Router::new()
@@ -30,6 +42,7 @@ pub fn router(dir: Shared) -> Router {
.route("/v1/blocked/{id}", delete(unblock))
.route("/v1/instances", get(instances))
.route("/v1/instances/{name}", delete(drop_instance))
.route_layer(axum::middleware::from_fn_with_state(WIRE, ipx_wire::negotiate))
.layer(axum::middleware::from_fn_with_state(dir.clone(), authenticate));
Router::new()
.route("/healthz", get(healthz))