The last parameter of every route handler is a Brisket response object - an environment agnostic set of tools for modifying the current resposne.
var BookRouter = Brisket.RouterBrewery.create({
routes: {
'books': 'books',
'books/:id': 'book'
},
books: function(layout, request, response) {
response.status(201); // server will respond with 201
return new BookView();
},
book: function(id, layout, request, response) {
var book = new Book({ id: id });
response.status(204); // server will respond with 204
return book.fetch()
.then(function() {
return new BookView({ model: book });
});
}
});var RouterBrewery = Brisket.RouterBrewery.makeBreweryWithDefaults({
onRouteStart: function(layout, request, response) {
response.status(202); // current history will be replaced with 'another/route'
}
});Here is a listing of all the tools provided by the Brisket response object.
Use this method to set the statusCode for the current response.
Use this method to set the response's HTTP header field to value. You can set multiple values by passing an object.
response.set('Content-Type', 'text/plain');
response.set({
'Content-Type': 'text/plain',
'Vary': 'Accept-Encoding',
'ETag': '12345'
});Use this method to redirect the current response to another uri. Example usage:
response.redirect('foo/bar');
response.redirect('/foo/bar');
response.redirect('http://example.com');
response.redirect(301, 'http://example.com');