Skip to content

Commit 94fbe7b

Browse files
committed
docs: Document after-response hooks
1 parent 91b1e79 commit 94fbe7b

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,33 @@ public class GetPromotionHandler implements RequestHandler {
343343
}
344344
```
345345

346+
### After-response hooks
347+
348+
Register code to run after the response has been sent. Hooks run on the request virtual thread,
349+
inside the library's request scope, with exceptions swallowed.
350+
351+
``` java
352+
OpenApiServer.builder()
353+
.spec(spec)
354+
.handlers(handlers)
355+
.afterResponseHook((req, resp) ->
356+
metrics.timer("http.request").record(req.operationId(), resp.status()))
357+
.build();
358+
```
359+
360+
Handlers can also queue per-request runnables:
361+
362+
``` java
363+
Map<String, RequestHandler> handlers = Map.of(
364+
"getThings", req -> {
365+
req.afterResponse(() -> auditLog.flush());
366+
return Response.ok(things);
367+
});
368+
```
369+
370+
Global hooks run first (registration order), then per-request runnables (FIFO). Pre-request
371+
failures (404, 405, validation) do not fire hooks.
372+
346373
### End-to-end example
347374

348375
Gson on the classpath for request/response JSON, SnakeYAML on the classpath for the spec, one interceptor binding a request-scoped tenant + correlation id, one decorator stamping the correlation id on every response, one handler. No extra wiring.

0 commit comments

Comments
 (0)