public interface RouteBuilder
Routes can be parsed from a String or created using this very builder. The toString() method of Route instances created using this builder output a String that is parseable by this builder.
Let's see some routes:
GET / controllers.Acme.index() GET /login controllers.Acme.loginForm() POST /login controllers.Acme.login() POST /subscribe controllers.Acme.subscribe() GET /:nickname controllers.Acme.home( String nickname )Here is a complete example using the API:
import io.werval.api.routes.Route; import io.werval.api.routes.RoutesBuilder; import static io.werval.api.routes.RoutesBuilder.p; RouteBuilder builder = ... ; // Route route = builder.route( "GET" ) .on( "/foo/:slug/bar/:id" ) .to( MyController.class, c -> c.another( p( "id", String.class ), p( "slug", Integer.class, 2 ) ) ) .build(); System.out.println( route.toString() );The last line would output:
GET /foo/bar/:id f.q.n.MyController.another( String id, Integer slug = 2 )
Modifier and Type | Interface and Description |
---|---|
static interface |
RouteBuilder.RouteDeclaration
Route Declaration.
|
static interface |
RouteBuilder.RouteParser
Route Parser.
|
Modifier and Type | Method and Description |
---|---|
static <T> T |
d(String name, Class<T> type, T defaultedValue)
Record a new method parameter with defaulted value.
|
static <T> T |
f(String name, Class<T> type, T forcedValue)
Record a new method parameter with forced value.
|
static <T> T |
p(String name, Class<T> type)
Record a new method parameter.
|
RouteBuilder.RouteParser |
parse()
Parse Routes from Strings.
|
RouteBuilder.RouteDeclaration |
route()
Start a RouteDeclaration.
|
RouteBuilder.RouteDeclaration |
route(Method httpMethod)
Start a RouteDeclaration for a HTTP method.
|
RouteBuilder.RouteDeclaration |
route(String httpMethod)
Start a RouteDeclaration for a HTTP method.
|
RouteBuilder.RouteDeclaration route()
RouteBuilder.RouteDeclaration route(String httpMethod)
httpMethod
- HTTP method
RouteBuilder.RouteDeclaration route(Method httpMethod)
httpMethod
- HTTP method
RouteBuilder.RouteParser parse()
static <T> T p(String name, Class<T> type)
T
- the parameterized parameter type
name
- the parameter name
type
- the parmeter type
static <T> T f(String name, Class<T> type, T forcedValue)
T
- the parameterized parameter type
name
- the parameter name
type
- the parmeter type
forcedValue
- the forced value