# Избор на начин за отговор

> Изпращайте JSON, HTML, обикновен текст, XML, пренасочвания, празни отговори или двоични данни от handler на маршрут.

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

Един handler отговаря на заявката, като извика един от методите за отговор на `$`. Всеки от тях задава вместо вас правилния `content-type`.

| Метод | Изпраща |
|---|---|
| `$.json(value)` | JSON |
| `$.html(string)` | HTML |
| `$.plain(string)` | обикновен текст |
| `$.xml(string)` | XML |
| `$.redirect(url, [permanent])` | пренасочване (302, или 301, когато `permanent` е true) |
| `$.empty()` | празен отговор (статус 204) |
| `$.binary(buffer, type)` | двоични данни със зададения 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'));
};
```
