mirror of
https://github.com/zap-proto/web.git
synced 2026-10-30 15:03:09 +00:00
httpServe(httpServer, opts) mounts POST /<service>/<method> on the SAME
http.Server, dispatching each request through the identical CallHandler that
serve() uses over WebSocket — one service implementation, reached two ways. The
paths match the OpenAPI 3.1 doc that `zapgen --emit=openapi` emits.
The JSON<->ZAP codec is schema-specific, so each method is supplied as an
HttpRoute {path, method ordinal, decode(json)->payloadBytes,
encode(bodyBytes)->json}; the generated zapgen bindings provide the struct
builders/views to fill those in. The runtime stays schema-agnostic. Auth reuses
the MintCap slot (null mint -> HTTP 401); ZAP error statuses map to HTTP 4xx/5xx.
httpServe owns `request` dispatch: it captures the app's existing listeners,
detaches them, and delegates unmatched paths back to them — guaranteeing exactly
one response writer per request even though route handling is async (mintCap,
body read). Node `http` only, no framework. Exported from @zap-proto/web/server.
Round-trip test: generate ts+openapi from a fixture .zap, validate every
components.schema under ajv 2020-12 (the dialect OpenAPI 3.1 mandates), spin
httpServe in-process, POST to the declared path, and assert the response
validates against the doc's 200 schema. Depends on @zap-proto/zap ^1.3.0.
21 lines
497 B
Plaintext
21 lines
497 B
Plaintext
package echo
|
|
|
|
# @openapi:version 1.0.0
|
|
# @openapi:server http://127.0.0.1/v1
|
|
|
|
# Request/response payloads for the EchoService.echo method.
|
|
struct EchoIn {
|
|
Msg text @0
|
|
}
|
|
|
|
struct EchoOut {
|
|
Msg text @0
|
|
}
|
|
|
|
# One method whose ordinal auto-assigns to 1. zapgen --emit=ts,openapi codegens
|
|
# both the EchoService Client/Server bindings AND the OpenAPI 3.1 doc whose
|
|
# POST /echo-service/echo path httpServe must serve.
|
|
interface EchoService {
|
|
echo(req: EchoIn) returns (resp: EchoOut)
|
|
}
|