Interface Router
- All Known Implementing Classes:
RouterImpl,RoutingBuilder
public interface Router
Interface for a router that maps HTTP request paths to handlers.
This interface provides methods to register handlers for different HTTP methods (GET, POST, PUT, DELETE, HEAD, OPTIONS, PATCH) with specified path patterns.
* Example usage:
Router router = Router.newRouter()
.get("/api/resource/:id", request -> {
return HttpResponse.ok(ContentType.TEXT_PLAIN, "Resource ID: " + request.getPathParameter("id");
})
.post("/api/resource", request -> {
// Handle POST request
});
-
Method Summary
Modifier and TypeMethodDescriptiondelete(String pathPattern, HttpRequestHandler handler) Registers a handler for DELETE method and path pattern.get(String pathPattern, HttpRequestHandler handler) Registers a handler for GET method and path pattern.head(String pathPattern, HttpRequestHandler handler) Registers a handler for HEAD method and path pattern.static RouterCreates a new router instance.options(String pathPattern, HttpRequestHandler handler) Registers a handler for OPTIONS method and path pattern.patch(String pathPattern, HttpRequestHandler handler) Registers a handler for PATCH method and path pattern.post(String pathPattern, HttpRequestHandler handler) Registers a handler for POST method and path pattern.put(String pathPattern, HttpRequestHandler handler) Registers a handler for PUT method and path pattern.
-
Method Details
-
get
Registers a handler for GET method and path pattern.- Parameters:
pathPattern- The path pattern to match against incoming requests.handler- The handler to be invoked when a request matches the specified method and path pattern.- Returns:
- The current Router instance for method chaining.
-
post
Registers a handler for POST method and path pattern.- Parameters:
pathPattern- The path pattern to match against incoming requests.handler- The handler to be invoked when a request matches the specified method and path pattern.- Returns:
- The current Router instance for method chaining.
-
put
Registers a handler for PUT method and path pattern.- Parameters:
pathPattern- The path pattern to match against incoming requests.handler- The handler to be invoked when a request matches the specified method and path pattern.- Returns:
- The current Router instance for method chaining.
-
delete
Registers a handler for DELETE method and path pattern.- Parameters:
pathPattern- The path pattern to match against incoming requests.handler- The handler to be invoked when a request matches the specified method and path pattern.- Returns:
- The current Router instance for method chaining.
-
head
Registers a handler for HEAD method and path pattern.- Parameters:
pathPattern- The path pattern to match against incoming requests.handler- The handler to be invoked when a request matches the specified method and path pattern.- Returns:
- The current Router instance for method chaining.
-
options
Registers a handler for OPTIONS method and path pattern.- Parameters:
pathPattern- The path pattern to match against incoming requests.handler- The handler to be invoked when a request matches the specified method and path pattern.- Returns:
- The current Router instance for method chaining.
-
patch
Registers a handler for PATCH method and path pattern.- Parameters:
pathPattern- The path pattern to match against incoming requests.handler- The handler to be invoked when a request matches the specified method and path pattern.- Returns:
- The current Router instance for method chaining.
-
newRouter
Creates a new router instance.- Returns:
- A new Router instance for method chaining.
-