public class RoutingDsl
extends java.lang.Object
import play.mvc.*; import play.routing.*; import play.libs.json.*; import play.api.routing.Router; public class MyRouterBuilder extends Controller { public Router getRouter() { return new RouterDsl() .GET("/hello/:to").routeTo(to -> ok("Hello " + to)) .POST("/api/items/:id").routeAsync((Integer id) -> { return Items.save(id, Json.fromJson(request().body().asJson(), Item.class) ).map(result -> ok("Saved item with id " + id)); }) .build(); } }The path pattern supports three different types of parameters, path segment parameters, prefixed with :, full path parameters, prefixed with *, and regular expression parameters, prefixed with $ and post fixed with a regular expression in angled braces.
Modifier and Type | Class and Description |
---|---|
class |
RoutingDsl.PathPatternMatcher
A matcher for routes.
|
Constructor and Description |
---|
RoutingDsl() |
Modifier and Type | Method and Description |
---|---|
play.api.routing.Router |
build()
Build the router.
|
RoutingDsl.PathPatternMatcher |
DELETE(java.lang.String pathPattern)
Create a DELETE route for the given path pattern.
|
RoutingDsl.PathPatternMatcher |
GET(java.lang.String pathPattern)
Create a GET route for the given path pattern.
|
RoutingDsl.PathPatternMatcher |
HEAD(java.lang.String pathPattern)
Create a HEAD route for the given path pattern.
|
RoutingDsl.PathPatternMatcher |
match(java.lang.String method,
java.lang.String pathPattern)
Create a route for the given method and path pattern.
|
RoutingDsl.PathPatternMatcher |
OPTIONS(java.lang.String pathPattern)
Create a OPTIONS route for the given path pattern.
|
RoutingDsl.PathPatternMatcher |
PATCH(java.lang.String pathPattern)
Create a PATCH route for the given path pattern.
|
RoutingDsl.PathPatternMatcher |
POST(java.lang.String pathPattern)
Create a POST route for the given path pattern.
|
RoutingDsl.PathPatternMatcher |
PUT(java.lang.String pathPattern)
Create a PUT route for the given path pattern.
|
public RoutingDsl.PathPatternMatcher GET(java.lang.String pathPattern)
pathPattern
- The path pattern.public RoutingDsl.PathPatternMatcher HEAD(java.lang.String pathPattern)
pathPattern
- The path pattern.public RoutingDsl.PathPatternMatcher POST(java.lang.String pathPattern)
pathPattern
- The path pattern.public RoutingDsl.PathPatternMatcher PUT(java.lang.String pathPattern)
pathPattern
- The path pattern.public RoutingDsl.PathPatternMatcher DELETE(java.lang.String pathPattern)
pathPattern
- The path pattern.public RoutingDsl.PathPatternMatcher PATCH(java.lang.String pathPattern)
pathPattern
- The path pattern.public RoutingDsl.PathPatternMatcher OPTIONS(java.lang.String pathPattern)
pathPattern
- The path pattern.public RoutingDsl.PathPatternMatcher match(java.lang.String method, java.lang.String pathPattern)
method
- The method;pathPattern
- The path pattern.public play.api.routing.Router build()