Expand description
POST/PUT/DELETE /sessions* REST routes over the session.*
JSON-RPC methods (#2983 Slice 3 — write routes).
Why: Slice 2 (super::sessions) covered the five read-only GET
routes; a REST client also needs to mint sessions, drive them, and
manage their goal slots without dropping to raw JSON-RPC. Every handler
below stays as thin as Slice 2’s — extract path/body, build the
JSON-RPC params, call super::respond (or [respond_created] for the
one route that needs a non-200 success status) — because the actual
behaviour (session lookup, validation, -32007 session_not_found
mapping, …) already lives in crate::session::protocol’s handlers;
duplicating it here as bespoke axum logic would fork the two surfaces
(see super module docs).
What: routes builds a standalone axum::Router<()> (its own
SessionsWriteState carrying just the Arc<Router>, with_state-erased
before return, mirroring super::sessions::SessionsState) mapping:
POST /sessions->session.create(201 Created— this route mints a brand-new resource, so it follows the standard REST creation convention rather than Slice 1-2’s uniform200/mapped-4xx; every other route below acts on an EXISTING resource, so it keeps200on success like every Slice 2 route)POST /sessions/{id}/messages->session.sendPOST /sessions/{id}/cancel->session.cancelPUT /sessions/{id}/goal->session.set_goalDELETE /sessions/{id}/goal->session.clear_goal
Request bodies deserialize into private structs shaped identically to
the RPC layer’s own params structs (crate::session::protocol’s
CreateParams/SendParams, protocol_goals’s
SetGoalParams/ClearGoalParams) minus whatever the URL path already
supplies (session_id) — a malformed body never reaches a handler at
all; axum’s Json<T> extractor rejects it before the handler runs
(400/422, see module docs on super), so no handler here
hand-rolls body validation.
crate::serve::http::build_axum_router merges this into the daemon’s
main router alongside POST /rpc, GET /health,
GET /sessions/{id}/events, and super::sessions’s read routes — none
of those paths collide with the ones here (PUT/DELETE /sessions/{id}/goal share a path with different methods, which axum
routes independently).
Test: tests::* (sessions_write_tests.rs, split out purely for the
500-SLOC cap — see crate::session::registry’s identical
#[path = "registry_tests.rs"] split for the established convention).
Functions§
- routes
- Build the
POST/PUT/DELETE /sessions*write route group.