public static class Route.Definition extends Object implements Route.Props<Route.Definition>
Some examples:
public class MyApp extends Jooby { { get("/", () -> "GET"); post("/", req -> "POST"); put("/", (req, rsp) -> rsp.send("PUT")); } }
public class MyApp extends Jooby { { post("/", (req, resp) -> resp.send("POST")) .consumes(MediaType.json); } }
public class MyApp extends Jooby { { post("/", (req, resp) -> resp.send("POST")) .produces(MediaType.json); } }
public class MyApp extends Jooby { { post("/", (req, resp) -> resp.send("POST")) .name("My Root"); } }
Constructor and Description |
---|
Definition(String method, String pattern, Route.Filter filter)
Creates a new route definition.
|
Definition(String method, String pattern, Route.Filter filter, boolean caseSensitiveRouting)
Creates a new route definition.
|
Definition(String verb, String pattern, Route.Handler handler)
Creates a new route definition.
|
Definition(String verb, String pattern, Route.Handler handler, boolean caseSensitiveRouting)
Creates a new route definition.
|
Definition(String verb, String pattern, Route.OneArgHandler handler)
Creates a new route definition.
|
Definition(String verb, String pattern, Route.ZeroArgHandler handler)
Creates a new route definition.
|
Modifier and Type | Method and Description |
---|---|
<T> T |
attr(String name)
Get an attribute by name.
|
Route.Definition |
attr(String name, Object value)
Set route attribute.
|
Map<String,Object> |
attributes() |
boolean |
canConsume(MediaType type)
Test if the route definition can consume a media type.
|
boolean |
canConsume(String type)
Test if the route definition can consume a media type.
|
boolean |
canProduce(List<MediaType> types)
Test if the route definition can consume a media type.
|
boolean |
canProduce(MediaType... types)
Test if the route definition can consume a media type.
|
boolean |
canProduce(String... types)
Test if the route definition can consume a media type.
|
List<MediaType> |
consumes() |
Route.Definition |
consumes(List<MediaType> types)
Set the media types the route can consume.
|
Route.Definition |
declaringClass(String declaringClass)
Set the class where this route is defined.
|
List<String> |
excludes() |
Route.Definition |
excludes(List<String> excludes)
Excludes one or more path pattern from this route, useful for filter:
|
Route.Filter |
filter() |
boolean |
glob()
|
Route.Definition |
line(int line)
Set the line where this route is defined.
|
Route.Definition |
map(Route.Mapper<?> mapper) |
Optional<Route> |
matches(String method, String path, MediaType contentType, List<MediaType> accept)
Test if the route matches the given verb, path, content type and accept header.
|
String |
method() |
String |
name()
Route's name, helpful for debugging but also to implement dynamic and advanced routing.
|
Route.Definition |
name(String name)
Set the route name.
|
String |
pattern()
Path Patterns
|
List<MediaType> |
produces() |
Route.Definition |
produces(List<MediaType> types)
Set the media types the route can produces.
|
String |
renderer()
Explicit renderer to use or null .
|
Route.Definition |
renderer(String name)
Tell jooby what renderer should use to render the output.
|
String |
reverse(Map<String,Object> vars)
Recreate a route path and apply the given variables.
|
String |
reverse(Object... values)
Recreate a route path and apply the given variables.
|
Route.Source |
source()
Source information (where the route was defined).
|
String |
toString() |
List<String> |
vars() |
public Definition(String verb, String pattern, Route.Handler handler)
verb
- A HTTP verb or *
.
pattern
- A path pattern.
handler
- A route handler.
public Definition(String verb, String pattern, Route.Handler handler, boolean caseSensitiveRouting)
verb
- A HTTP verb or *
.
pattern
- A path pattern.
handler
- A route handler.
caseSensitiveRouting
- Configure case for routing algorithm.
public Definition(String verb, String pattern, Route.OneArgHandler handler)
verb
- A HTTP verb or *
.
pattern
- A path pattern.
handler
- A route handler.
public Definition(String verb, String pattern, Route.ZeroArgHandler handler)
verb
- A HTTP verb or *
.
pattern
- A path pattern.
handler
- A route handler.
public Definition(String method, String pattern, Route.Filter filter)
method
- A HTTP verb or *
.
pattern
- A path pattern.
filter
- A callback to execute.
public Definition(String method, String pattern, Route.Filter filter, boolean caseSensitiveRouting)
method
- A HTTP verb or *
.
pattern
- A path pattern.
filter
- A callback to execute.
caseSensitiveRouting
- Configure case for routing algorithm.
@Nonnull public String pattern()
Jooby supports Ant-style path patterns:
Some examples:
com/t?st.html
- matches com/test.html
but also com/tast.jsp
or com/txst.html
com/*.html
- matches all .html
files in the com
directorycom/**/test.html
- matches all test.html
files underneath the com
path**
/*
- matches any path at any level.*
- matches any path at any level, shorthand for **
/*
.Jooby supports path parameters too:
Some examples:
/user/{id}
- /user/* and give you access to the id
var. /user/:id
- /user/* and give you access to the id
var. /user/{id:\\d+}
- /user/[digits] and give you access to the numeric id
var.@Nullable public String renderer()
Route.Props
null
.
renderer
in interface Route.Props<Route.Definition>
null
.
public Route.Definition renderer(String name)
Route.Props
renderer
in interface Route.Props<Route.Definition>
name
- A renderer's name.
@Nonnull public boolean glob()
pattern()
contains a glob charecter, like ?
, *
or **
.
@Nonnull public Route.Source source()
@Nonnull public String reverse(Map<String,Object> vars)
vars
- Path variables.
@Nonnull public String reverse(Object... values)
values
- Path variable values.
@Nonnull public Route.Definition attr(String name, Object value)
Route.Props
attr
in interface Route.Props<Route.Definition>
name
- Attribute's name.
value
- Attribute's value.
@Nonnull public <T> T attr(String name)
T
- Attribute's type.
name
- Attribute's name.
null
.
@Nonnull public Optional<Route> matches(String method, String path, MediaType contentType, List<MediaType> accept)
method
- A HTTP verb.
path
- Current HTTP path.
contentType
- The Content-Type
header.
accept
- The Accept
header.
@Nonnull public Route.Filter filter()
@Nonnull public String name()
Route.Chain.next(String, Request, Response)
anonymous
.
@Nonnull public Route.Definition name(String name)
Route.Chain.next(String, Request, Response)
name
in interface Route.Props<Route.Definition>
name
- A route's name.
public boolean canConsume(MediaType type)
type
- A media type to test.
public boolean canConsume(String type)
type
- A media type to test.
public boolean canProduce(List<MediaType> types)
types
- A media types to test.
public boolean canProduce(MediaType... types)
types
- A media types to test.
public boolean canProduce(String... types)
types
- A media types to test.
public Route.Definition consumes(List<MediaType> types)
Route.Props
consumes
in interface Route.Props<Route.Definition>
types
- The media types to test for.
public Route.Definition produces(List<MediaType> types)
Route.Props
produces
in interface Route.Props<Route.Definition>
types
- The media types to test for.
public Route.Definition excludes(List<String> excludes)
Route.Props
{ use("*", req -> { ... }).excludes("/logout"); }
excludes
in interface Route.Props<Route.Definition>
excludes
- A path pattern.
@Nonnull public Route.Definition map(Route.Mapper<?> mapper)
map
in interface Route.Props<Route.Definition>
@Nonnull public Route.Definition line(int line)
line
- Line number.
@Nonnull public Route.Definition declaringClass(String declaringClass)
declaringClass
- A source class.
Copyright © 2019. All rights reserved.