# Alegerea modului de a răspunde

> Trimite JSON, HTML, text simplu, XML, redirecționări, răspunsuri goale sau date binare dintr-un handler de rută.

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

Un handler răspunde cererii apelând una dintre metodele de răspuns ale lui `$`. Fiecare setează `content-type`-ul corect pentru tine.

| Metodă | Trimite |
|---|---|
| `$.json(value)` | JSON |
| `$.html(string)` | HTML |
| `$.plain(string)` | text simplu |
| `$.xml(string)` | XML |
| `$.redirect(url, [permanent])` | o redirecționare (302, sau 301 când `permanent` este true) |
| `$.empty()` | un răspuns gol (status 204) |
| `$.binary(buffer, type)` | date binare cu content type-ul dat |

```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'));
};
```
