# Vyber, ako odpovedať

> Posielaj JSON, HTML, čistý text, XML, presmerovania, prázdne odpovede alebo binárne dáta z handlera cesty.

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

Handler odpovie na požiadavku zavolaním jednej z metód odpovede objektu `$`. Každá nastaví správny `content-type` za teba.

| Metóda | Posiela |
|---|---|
| `$.json(value)` | JSON |
| `$.html(string)` | HTML |
| `$.plain(string)` | čistý text |
| `$.xml(string)` | XML |
| `$.redirect(url, [permanent])` | presmerovanie (302, alebo 301, ak je `permanent` true) |
| `$.empty()` | prázdna odpoveď (stav 204) |
| `$.binary(buffer, type)` | binárne dáta so zadaným 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'));
};
```
