host: Phase 1 — router + handler + GET /feed endpoint on Dream, 28/28
First migrated endpoint onto the SX host. lib/host is a thin wiring layer: a host handler is a Dream handler (request->response) that calls a subsystem public API and serialises via a shared JSON envelope. - handler.sx: host/ok, host/ok-status, host/error, host/json-status (Dream's dream-json is 200-only), host/query-int - router.sx: host/make-app assembles per-domain route groups + /health probe into one dream-router (reuses dr/flatten-routes) - feed.sx: GET /feed reads feed/all + stream combinators, recent-first, with ?actor= filter and ?limit= cap - 3 test suites incl. a golden test (body == subsystem recent stream + envelope) - conformance.sh mirrors lib/dream's runner Builds on dream-on-sx (merged, gate green 480/480) rather than a throwaway native request model; collapses most of plan Phase 4 into Phase 1. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
39
lib/host/handler.sx
Normal file
39
lib/host/handler.sx
Normal file
@@ -0,0 +1,39 @@
|
||||
;; lib/host/handler.sx — Host handler layer: the bridge from a Dream request to a
|
||||
;; subsystem call and back to a Dream response. A host handler IS a Dream handler
|
||||
;; (request -> response); these helpers build the JSON envelope every host
|
||||
;; endpoint shares: {"ok":true,"data":...} on success, {"ok":false,"error":...}
|
||||
;; on failure. Plus a status-carrying JSON constructor that Dream's own dream-json
|
||||
;; (200-only) lacks, and a couple of request-reading conveniences.
|
||||
;; Depends on lib/dream/types.sx + lib/dream/json.sx.
|
||||
|
||||
;; ── responses ──────────────────────────────────────────────────────
|
||||
|
||||
;; JSON response at an arbitrary status (dream-json is 200-only).
|
||||
(define host/json-status
|
||||
(fn (status value)
|
||||
(dream-response status {:content-type "application/json"}
|
||||
(dream-json-encode value))))
|
||||
|
||||
;; Success envelope: 200 {"ok":true,"data":<value>}.
|
||||
(define host/ok
|
||||
(fn (value)
|
||||
(host/json-status 200 {:ok true :data value})))
|
||||
|
||||
;; Success envelope at a chosen status (e.g. 201 for a created resource).
|
||||
(define host/ok-status
|
||||
(fn (status value)
|
||||
(host/json-status status {:ok true :data value})))
|
||||
|
||||
;; Error envelope: {"ok":false,"error":<message>} at the given status.
|
||||
(define host/error
|
||||
(fn (status message)
|
||||
(host/json-status status {:ok false :error message})))
|
||||
|
||||
;; ── request reading ────────────────────────────────────────────────
|
||||
|
||||
;; Integer query param with a fallback (query params arrive as strings).
|
||||
;; Absent param -> fallback; present -> parsed number.
|
||||
(define host/query-int
|
||||
(fn (req name fallback)
|
||||
(let ((raw (dream-query-param req name)))
|
||||
(if raw (string->number raw) fallback))))
|
||||
Reference in New Issue
Block a user