{#========================================== Spincast Response plugin ==========================================#} {% extends "../../layout.html" %} {% block sectionClasses %}plugins hasBreadCrumb plugins-spincast-response{% endblock %} {% block meta_title %}Plugins - Spincast Response{% endblock %} {% block meta_description %}Spincast Response plugin to manipulate the headers and content sent.{% endblock %} {% block scripts %} {% endblock %} {% block body %}
The Spincast Response plugin provides a Request Context add-on :
ResponseRequestContextAddon.
This add-on helps you build a response to the current HTTP request. It allows you to manipulate the
HTTP headers and provides utilities to build the body. It is mounted as .response()
on the default Spincast Request Context.
Make sure you read the dedicated Sending the response
section for more information.
.response() add-on from a Route Handler
to send content directly :
public void myHandler(AppRequestContext context) {
context.response().setStatusCode(418);
context.response().sendPlainText("Drink tea!");
}
response model and render HTML
using a template :
public void myHandler(AppRequestContext context) {
//...
context.response().getModel().put("user", someUser);
context.response().sendTemplateHtml("/templates/user.html");
}
If you use the spincast-default artifact, this plugin is already installed so
you have nothing more to do!
If you start from scratch using the spincast-core artifact, you can use the
plugin by adding this artifact to your project:
<dependency>
<groupId>org.spincast</groupId>
<artifactId>spincast-plugins-response</artifactId>
<version>{{spincast.spincastCurrrentVersion}}</version>
</dependency>
You then install the plugin's Guice module, by passing it to the Guice.createInjector(...) method:
Injector guice = Guice.createInjector(
new SpincastCoreGuiceModule(args),
new SpincastResponsePluginGuiceModule(AppRequestContext.class, AppWebsocketContext.class)
// other modules...
);
... or by using the install(...) method from your custom Guice module:
public class AppModule extends SpincastCoreGuiceModule {
@Override
protected void configure() {
super.configure();
install(new SpincastResponsePluginGuiceModule(getRequestContextType(),
getWebsocketContextType()));
// other modules...
}
// ...
}