# Kiezen hoe je antwoordt

> Stuur JSON, HTML, platte tekst, XML, redirects, lege antwoorden of binaire gegevens vanuit een route-handler.

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

Een handler beantwoordt het verzoek door een van de antwoordmethoden van `$` aan te roepen. Elke methode stelt de juiste `content-type` voor je in.

| Methode | Stuurt |
|---|---|
| `$.json(value)` | JSON |
| `$.html(string)` | HTML |
| `$.plain(string)` | platte tekst |
| `$.xml(string)` | XML |
| `$.redirect(url, [permanent])` | een redirect (302, of 301 wanneer `permanent` true is) |
| `$.empty()` | een leeg antwoord (status 204) |
| `$.binary(buffer, type)` | binaire gegevens met het opgegeven 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'));
};
```
