public static interface Response.Formatter
{{ get("/", (req, resp) -> { Object model = ...; resp.when("text/html", () -> Viewable.of("view", model)) .when("application/json", () -> model) .send(); }); }}The example above will render a view when accept header is "text/html" or just send a text version of model when the accept header is "application/json".
Modifier and Type | Method and Description |
---|---|
void |
send()
Send the response.
|
Response.Formatter |
when(MediaType type,
ExSupplier<Object> supplier)
Add a new when clause for a custom media-type.
|
default Response.Formatter |
when(String type,
ExSupplier<Object> supplier)
Add a new when clause for a custom media-type.
|
@Nonnull default Response.Formatter when(String type, @Nonnull ExSupplier<Object> supplier)
type
- A media type to test for.supplier
- An object supplier.Response.Formatter
.@Nonnull Response.Formatter when(MediaType type, @Nonnull ExSupplier<Object> supplier)
type
- A media type to test for.supplier
- An object supplier.Response.Formatter
.Copyright © 2014. All rights reserved.