HTTP Context
Use ctx.session() to access query parameters, headers, and cookies within any pipeline step:
@Overridepublic RequestPipeline<EchoResponse> handle(HttpStream<EchoRequest, MyState> e) { return e.complete(ctx -> { // Read from request String query = ctx.session().getQueryParam("search"); String header = ctx.session().getRequestHeader("X-Request-Id"); HttpCookie cookie = ctx.session().getRequestCookie("session");
// Write to response ctx.session().addResponseHeader("X-Response-Id", "abc"); ctx.session().addResponseCookie(new HttpCookie("session", "new-value"));
return HttpResult.success(new EchoResponse(query, header)); });}Available Methods
Section titled “Available Methods”Reading from the Request
Section titled “Reading from the Request”| Method | Description |
|---|---|
getQueryParam(name) | Get a query parameter value |
getRequestHeader(name) | Get a request header value |
getRequestCookie(name) | Get a request cookie |
getPathParam(name) | Get a path parameter value |
Writing to the Response
Section titled “Writing to the Response”| Method | Description |
|---|---|
addResponseHeader(name, value) | Add a response header |
addResponseCookie(cookie) | Add a response cookie |