public static interface Parser.Builder
Upload
or HTTP Parser.BodyReference
.
This class provides utility methods for selecting one of the previous source. It is possible to
write a parser and apply it against multiple sources, like HTTP param and HTTP body.
Here is an example that will parse text to an int, provided as a HTTP param or body:
{ parser((type, ctx) -> { if (type.getRawType() == int.class) { return ctx .param(values -> Integer.parseInt(values.get(0)) .body(body -> Integer.parseInt(body.text())); } return ctx.next(); }); get("/", req -> { // use the param strategy return req.param("p").intValue(); }); post("/", req -> { // use the body strategy return req.body().intValue(); }); }
Modifier and Type | Method and Description |
---|---|
Parser.Builder |
body(Parser.Callback<Parser.BodyReference> callback)
Add a HTTP body callback.
|
Parser.Builder |
ifbody(Parser.Callback<Parser.BodyReference> callback)
Like
#body(Callback) but it skip the callback if the requested type is an
Optional . |
Parser.Builder |
ifparam(Parser.Callback<Parser.ParamReference<String>> callback)
Like
#param(Callback) but it skip the callback if the requested type is an
Optional . |
Parser.Builder |
ifparams(Parser.Callback<Map<String,Mutant>> callback)
Like
#params(Callback) but it skip the callback if the requested type is an
Optional . |
Parser.Builder |
ifupload(Parser.Callback<Parser.ParamReference<Upload>> callback)
Like
#upload(Callback) but it skip the callback if the requested type is an
Optional . |
Parser.Builder |
param(Parser.Callback<Parser.ParamReference<String>> callback)
Add a HTTP param callback.
|
Parser.Builder |
params(Parser.Callback<Map<String,Mutant>> callback)
Add a HTTP params callback.
|
Parser.Builder |
upload(Parser.Callback<Parser.ParamReference<Upload>> callback)
Add a HTTP upload callback.
|
Parser.Builder body(Parser.Callback<Parser.BodyReference> callback)
Request.body()
.
If current Parser.Context
isn't a HTTP body a call to Parser.Context.next()
is made.callback
- A body parser callback.Parser.Builder ifbody(Parser.Callback<Parser.BodyReference> callback)
#body(Callback)
but it skip the callback if the requested type is an
Optional
.callback
- A body parser callback.Parser.Builder param(Parser.Callback<Parser.ParamReference<String>> callback)
Request.param(String)
.
If current Parser.Context
isn't a HTTP param a call to Parser.Context.next()
is made.callback
- A param parser callback.Parser.Builder ifparam(Parser.Callback<Parser.ParamReference<String>> callback)
#param(Callback)
but it skip the callback if the requested type is an
Optional
.callback
- A param parser callback.Parser.Builder params(Parser.Callback<Map<String,Mutant>> callback)
Request.params()
.
If current Parser.Context
isn't a HTTP params a call to Parser.Context.next()
is made.callback
- A params parser callback.Parser.Builder ifparams(Parser.Callback<Map<String,Mutant>> callback)
#params(Callback)
but it skip the callback if the requested type is an
Optional
.callback
- A params parser callback.Parser.Builder upload(Parser.Callback<Parser.ParamReference<Upload>> callback)
Request.param(String)
.
If current Parser.Context
isn't a HTTP upload a call to Parser.Context.next()
is made.callback
- A upload parser callback.Parser.Builder ifupload(Parser.Callback<Parser.ParamReference<Upload>> callback)
#upload(Callback)
but it skip the callback if the requested type is an
Optional
.callback
- A upload parser callback.Copyright © 2016. All rights reserved.