public interface Request extends Locals
Modifier and Type | Interface and Description |
---|---|
static class |
Request.Forwarding
Forwarding request.
|
static interface |
Request.Module
Jooby doesn't use a custom scope annotation for request scoped object.
|
Modifier and Type | Method and Description |
---|---|
List<MediaType> |
accept() |
Optional<MediaType> |
accepts(List<MediaType> types)
Check if the given types are acceptable, returning the best match when true, or else
Optional.empty.
|
default Optional<MediaType> |
accepts(MediaType... types)
Check if the given types are acceptable, returning the best match when true, or else
Optional.empty.
|
default Optional<MediaType> |
accepts(String... types)
Check if the given types are acceptable, returning the best match when true, or else
Optional.empty.
|
default <T> T |
body(Class<T> type)
Convert the HTTP request body into the given type.
|
<T> T |
body(com.google.inject.TypeLiteral<T> type)
Convert the HTTP request body into the given type.
|
Charset |
charset()
The charset defined in the request body.
|
Optional<Cookie> |
cookie(String name)
Get a cookie with the given name (if present).
|
List<Cookie> |
cookies() |
Mutant |
header(String name)
Get a HTTP header.
|
Map<String,Mutant> |
headers() |
String |
hostname()
The fully qualified name of the client or the last proxy that sent the request.
|
Optional<Session> |
ifSession() |
String |
ip() |
long |
length() |
Locale |
locale()
Get the content of the
Accept-Language header. |
Mutant |
param(String name)
Get a HTTP request parameter under the given name.
|
Map<String,Mutant> |
params()
Get all the available parameters.
|
<T> T |
params(Class<T> beanType)
Inject headers, path and query params into the given type.
|
default String |
path()
Given:
|
String |
protocol() |
default <T> T |
require(Class<T> type)
Ask Guice for the given type.
|
<T> T |
require(com.google.inject.Key<T> key)
Ask Guice for the given type.
|
default <T> T |
require(com.google.inject.TypeLiteral<T> type)
Ask Guice for the given type.
|
Route |
route() |
boolean |
secure() |
Session |
session() |
Request |
set(String name,
Object value)
Set a local using a the given name.
|
MediaType |
type() |
Request |
unset()
Unset/remove all the session data.
|
default Verb |
verb() |
default boolean |
xhr() |
attributes, get, isSet, unset
@Nonnull default String path()
http://domain.com/some/path.html -> /some/path.html http://domain.com/a.html -> /a.html
default Verb verb()
@Nonnull default Optional<MediaType> accepts(@Nonnull String... types)
// Accept: text/html req.accepts("text/html"); // => "text/html" // Accept: text/*, application/json req.accepts("text/html"); // => "text/html" req.accepts("text/html"); // => "text/html" req.accepts("application/json" "text/plain"); // => "application/json" req.accepts("application/json"); // => "application/json" // Accept: text/*, application/json req.accepts("image/png"); // => Optional.empty // Accept: text/*;q=.5, application/json req.accepts("text/html", "application/json"); // => "application/json"
types
- Types to test.@Nonnull default Optional<MediaType> accepts(@Nonnull MediaType... types)
// Accept: text/html req.accepts("text/html"); // => "text/html" // Accept: text/*, application/json req.accepts("text/html"); // => "text/html" req.accepts("text/html"); // => "text/html" req.accepts("application/json" "text/plain"); // => "application/json" req.accepts("application/json"); // => "application/json" // Accept: text/*, application/json req.accepts("image/png"); // => Optional.empty // Accept: text/*;q=.5, application/json req.accepts("text/html", "application/json"); // => "application/json"
types
- Types to test.@Nonnull Optional<MediaType> accepts(@Nonnull List<MediaType> types)
// Accept: text/html req.accepts("text/html"); // => "text/html" // Accept: text/*, application/json req.accepts("text/html"); // => "text/html" req.accepts("text/html"); // => "text/html" req.accepts("application/json" "text/plain"); // => "application/json" req.accepts("application/json"); // => "application/json" // Accept: text/*, application/json req.accepts("image/png"); // => Optional.empty // Accept: text/*;q=.5, application/json req.accepts("text/html", "application/json"); // => "application/json"
types
- Types to test for.@Nonnull Map<String,Mutant> params() throws Exception
/path/:name
or /path/{name}
?name=jooby
Content-Type
is
application/x-www-form-urlencoded
or multipart/form-data
Exception
- On param retrieval failures.<T> T params(Class<T> beanType) throws Exception
/path/:name
or /path/{name}
?name=jooby
Exception
- On param retrieval failures.@Nonnull Mutant param(@Nonnull String name) throws Exception
/path/:name
or /path/{name}
?name=jooby
Content-Type
is
application/x-www-form-urlencoded
or multipart/form-data
path
, query
and body
. For
example a pattern like: GET /path/:name
for /path/jooby?name=rocks
produces:
assertEquals("jooby", req.param(name).stringValue()); assertEquals("jooby", req.param(name).toList(String.class).get(0)); assertEquals("rocks", req.param(name).toList(String.class).get(1));Uploads can be retrieved too when
Content-Type
is multipart/form-data
see Upload
for more information.name
- A parameter's name.Exception
- On param retrieval failures.@Nonnull Mutant header(@Nonnull String name)
name
- A header's name.@Nonnull Optional<Cookie> cookie(@Nonnull String name)
name
- Cookie's name.@Nonnull default <T> T body(@Nonnull Class<T> type) throws Exception
T
- Body type.type
- A body type.Exception
- If body can't be converted or there is no HTTP body.@Nonnull <T> T body(@Nonnull com.google.inject.TypeLiteral<T> type) throws Exception
T
- Body type.type
- A body type.Exception
- If body can't be converted or there is no HTTP body.@Nonnull default <T> T require(@Nonnull Class<T> type)
T
- Service type.type
- A service type.Request.Module
@Nonnull default <T> T require(@Nonnull com.google.inject.TypeLiteral<T> type)
T
- Service type.type
- A service type.Request.Module
@Nonnull <T> T require(@Nonnull com.google.inject.Key<T> key)
T
- Service type.key
- A service key.Request.Module
@Nonnull Charset charset()
application.charset
.@Nonnull Locale locale()
Accept-Language
header. If the request doens't specify
such header, this method return the global locale: application.lang
.long length()
-1
if the length is not known.String hostname()
Session session()
Optional<Session> ifSession()
default boolean xhr()
X-Requested-With
header is set to XMLHttpRequest
.String protocol()
boolean secure()
Request set(String name, Object value)
Locals
Copyright © 2015. All rights reserved.