public static class Route.Definition extends Object implements Route.Props<Route.Definition>
It's pretty straight forward:
public class MyApp extends Jooby { { get("/", (req, rsp) -> rsp.send("GET")); post("/", (req, rsp) -> rsp.send("POST")); put("/", (req, rsp) -> rsp.send("PUT")); delete("/", (req, rsp) -> rsp.status(Response.Status.NO_CONTENT)); } }
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 verb,
String pattern,
Route.Handler handler)
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 |
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.
|
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.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 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.public boolean glob()
pattern()
contains a glob charecter, like ?
,
*
or **
.public String reverse(Map<String,Object> vars)
vars
- Path variables.public String reverse(Object... values)
values
- Path variable values.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.public <T> T attr(String name)
T
- Attribute's type.name
- Attribute's name.null
.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.public String method()
*
.public Route.Filter filter()
public String name()
Route.Chain.next(String, Request, Response)
anonymous
.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.public Route.Definition map(Route.Mapper<?> mapper)
map
in interface Route.Props<Route.Definition>
public Route.Definition line(int line)
line
- Line number.public Route.Definition declaringClass(String declaringClass)
declaringClass
- A source class.Copyright © 2016. All rights reserved.