io.quarkus.vertx.web.RoutingExchange Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-reactive-routes Show documentation
Show all versions of quarkus-reactive-routes Show documentation
REST framework offering the route model to define non blocking endpoints
package io.quarkus.vertx.web;
import java.util.Optional;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.ext.web.RoutingContext;
/**
* Convenient wrapper of {@link RoutingContext}.
*/
public interface RoutingExchange {
/**
* @return the underlying Vert.x routing context.
*/
RoutingContext context();
/**
* @return the HTTP request object
*/
default HttpServerRequest request() {
return context().request();
}
/**
*
* @param paramName
* @return the request parameter
* @see HttpServerRequest#getParam(String)
*/
default Optional getParam(String paramName) {
return Optional.ofNullable(request().getParam(paramName));
}
/**
*
* @param headerName
* @return the first header value with the specified name
* @see HttpServerRequest#getHeader(CharSequence)
*/
default Optional getHeader(CharSequence headerName) {
return Optional.ofNullable(request().getHeader(headerName));
}
/**
* @return the HTTP response object
*/
default HttpServerResponse response() {
return context().response();
}
/**
* Set the response status code to 200 and return the response.
* You must call HttpServerResponse.end()
afterwards to end the response.
*
* @return the HTTP response object
*/
default HttpServerResponse ok() {
return response().setStatusCode(200);
}
/**
* Set the response status code to 200, write a chunk of data to the response then ends it.
*
* @param chunk
*/
default void ok(String chunk) {
ok().end(chunk);
}
/**
* Set the response status code to 500 and return the response.
* You must call HttpServerResponse.end()
afterwards to end the response.
*
* @return the HTTP response object
*/
default HttpServerResponse serverError() {
return response().setStatusCode(500);
}
/**
* Set the response status code to 404 and return the response.
* You must call HttpServerResponse.end()
afterwards to end the response.
*
* @return the HTTP response object
*/
default HttpServerResponse notFound() {
return response().setStatusCode(404);
}
}