feat(api): add HTTP REST API server with SSE streaming#350
Merged
pocky merged 1 commit intoMay 17, 2026
Conversation
- `.go-arch-lint.yml`: Add root vendor entries for huma/v2 and chi/v5 - `CHANGELOG.md`: Document F097 HTTP REST API server feature - `CLAUDE.md`: Add architecture rules for HTTP server and mutex patterns - `README.md`: Add awf serve command reference - `docs/ADR/README.md`: Reference ADR-016 for HTTP interface adapter - `docs/README.md`: Add api.md to user guide index - `docs/user-guide/api.md`: Add complete HTTP API reference and examples - `docs/user-guide/commands.md`: Document awf serve command - `internal/application/execution_service.go`: Add ResumeExecution method - `internal/domain/workflow/context.go`: Add thread-safe getters and setters - `internal/interfaces/api/bridge.go`: Implement Bridge adapter with sync.Map execution tracking - `internal/interfaces/api/doc.go`: Add architecture overview and component descriptions - `internal/interfaces/api/handlers_executions.go`: Implement execution lifecycle handlers - `internal/interfaces/api/handlers_executions_test.go`: Update tests for execution handlers - `internal/interfaces/api/handlers_history.go`: Add history and stats endpoint handlers - `internal/interfaces/api/handlers_history_test.go`: Add history handler unit tests - `internal/interfaces/api/server.go`: Implement HTTP server with Huma/chi and graceful shutdown - `internal/interfaces/api/server_test.go`: Add server route registration and lifecycle tests - `internal/interfaces/api/sse.go`: Implement SSE streaming with 200ms polling cadence - `internal/interfaces/api/sse_test.go`: Add SSE handler and event constant tests - `internal/interfaces/cli/root.go`: Register serve subcommand - `internal/interfaces/cli/serve.go`: Add awf serve CLI command with host/port/timeout flags - `internal/interfaces/cli/serve_test.go`: Add serve command unit tests - `tests/fixtures/api/api-failing.yaml`: Add failing workflow fixture - `tests/fixtures/api/api-simple-success.yaml`: Add simple success workflow fixture - `tests/fixtures/api/api-slow.yaml`: Add slow workflow fixture for SSE tests - `tests/integration/api/functional_test.go`: Add functional API integration tests - `tests/integration/api/server_integration_test.go`: Add server integration tests - `tests/integration/testhelpers/helpers.go`: Add API test helper utilities Closes #349
52a43da to
36b151b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
awf servecommand that exposes the full AWF workflow engine over HTTP, enabling remote execution and monitoring without shelling out to the CLI/api/workflows,/api/executions,/api/history) with async workflow launch (202 Accepted +execution_id), lifecycle control (cancel, resume), and real-time Server-Sent Events streaming per executioninternal/interfaces/api/) using Huma v2 + chi v5, with auto-generated OpenAPI 3.1 spec and Swagger UI at/docs; arch-lint enforces the layer boundary (no infra imports)ExecutionContextby adding mutex-protected getters/setters required by the SSE streaming goroutines; document bridge shutdown sequence (httpSrv.Shutdown → sseWG.Wait)Changes
API Layer (new interface adapter)
internal/interfaces/api/server.go: HTTP server struct with Huma/chi wiring, graceful shutdown (30s drain),ReadHeaderTimeoutanti-Slowloris, route registrationinternal/interfaces/api/server_test.go: Unit tests for server struct — route registration, graceful shutdown, API initializationinternal/interfaces/api/bridge.go: Bridge adapter wrappingWorkflowService/ExecutionService;sync.Maptracks active executions; mirrorstui/bridge.gopatterninternal/interfaces/api/handlers_executions.go: Handlers for workflow run, list/get/cancel/resume executions, SSE streaming endpointinternal/interfaces/api/handlers_history.go: Handlers forGET /api/historywith filtering (workflow, status, since/until) andGET /api/history/statsinternal/interfaces/api/handlers_history_test.go: Unit tests for history and stats handlersinternal/interfaces/api/handlers_executions_test.go: Updated execution handler testsinternal/interfaces/api/sse.go: SSE event types, constants, 200ms-polling stream loop,sync.WaitGroup-tracked goroutines, auto-close on terminal stateinternal/interfaces/api/sse_test.go: SSE event struct, constant, and streaming behavior testsinternal/interfaces/api/doc.go: Architecture overview and component descriptions for theapipackageCLI Command
internal/interfaces/cli/serve.go:awf serveCobra command with--host/--portflags, pack discoverer wiring,signal.NotifyContextshutdown, startup/shutdown log messagesinternal/interfaces/cli/serve_test.go: Unit tests for serve command flag parsing and defaultsinternal/interfaces/cli/root.go: RegisterservesubcommandDomain & Application
internal/domain/workflow/context.go: Add mutex-protectedGetStartedAt,SetStartedAt,GetCompletedAt,SetCompletedAtgetters/setters for concurrent SSE accessinternal/application/execution_service.go: Use newExecutionContextsetter methods; exposeGetActiveExecutionsfor bridge pollingConfiguration & Architecture
.go-arch-lint.yml: Addinterfaces-apicomponent withhumaandchivendor entries; enforce layer isolationCLAUDE.md: Add architecture rules for mutex-protected state and server WaitGroup shutdown pattern; add test conventions for HTTP server unit tests and fixture organizationDocumentation
docs/user-guide/api.md: Complete HTTP API reference — all endpoints, request/response examples (Huma envelope format, RFC 7807 errors), SSE event types, cURL/JS/Python client examples, security considerationsdocs/user-guide/commands.md: Addawf servecommand reference with flagsdocs/README.md: Link to new API user guidedocs/ADR/README.md: Register ADR-015 (gRPC plugin transport) and ADR-016 (HTTP interface adapter with Huma + SSE)README.md: Add HTTP REST API feature bullet andawf servecommand to the command tableCHANGELOG.md: Document F097 in[Unreleased]sectionTest Fixtures & Integration Tests
tests/fixtures/api/api-simple-success.yaml: Minimal two-step workflow fixture for success pathtests/fixtures/api/api-failing.yaml: Workflow fixture that fails for error-path coveragetests/fixtures/api/api-slow.yaml: Slow-running workflow fixture for SSE streaming teststests/integration/api/functional_test.go: End-to-end functional tests — workflow discovery, async run, SSE streaming, cancel, historytests/integration/api/server_integration_test.go: Server lifecycle integration tests — startup, shutdown, route availabilitytests/integration/testhelpers/helpers.go: Shared test helper utilities extended for API test setupTest plan
make buildsucceeds andawf serve --helpshows--host/--portflagsawf serve, openhttp://localhost:2511/docsin a browser — Swagger UI loads and all routes are listedPOST /api/workflows/<name>/runreturns 202, thenGET /api/executions/{id}/eventsstreamsstep.started/step.completed/workflow.completedevents and closes the connectionmake test-racepasses with zero data races across theinternal/interfaces/api/packageCloses #349
Generated with awf commit workflow