# Choose how to respond

> Send JSON, HTML, plain text, XML, redirects, empty responses or binary data from a route handler.

Framework: total5
Product: Total.js 5 (total5@0.0.19)
Language: en
Content-SHA256: 0298973310cdc200347a02f33052883d73657d0a5e6348a855a3a8a783c2a4d7
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: total5-installed@total5@0.0.19
Review: not-recorded

A handler answers the request by calling one of the response methods of `$`. Each one sets the right `content-type` for you.

| Method | Sends |
|---|---|
| `$.json(value)` | JSON |
| `$.html(string)` | HTML |
| `$.plain(string)` | plain text |
| `$.xml(string)` | XML |
| `$.redirect(url, [permanent])` | a redirect (302, or 301 when `permanent` is true) |
| `$.empty()` | an empty response (status 204) |
| `$.binary(buffer, type)` | binary data with the given content type |

```js controllers/responses.js
exports.install = function() {
	ROUTE('GET /json/', ($) => $.json({ ok: true }));
	ROUTE('GET /html/', ($) => $.html('<h1>Hello</h1>'));
	ROUTE('GET /plain/', ($) => $.plain('Hello'));
	ROUTE('GET /xml/', ($) => $.xml('<root><item>1</item></root>'));
	ROUTE('GET /redirect/', ($) => $.redirect('/json/'));
	ROUTE('GET /moved/', ($) => $.redirect('/json/', true));
	ROUTE('GET /empty/', ($) => $.empty());
	ROUTE('GET /binary/', ($) => $.binary(Buffer.from('abc'), 'application/octet-stream'));
};
```
