# Wybór sposobu odpowiedzi

> Wysyłaj JSON, HTML, zwykły tekst, XML, przekierowania, puste odpowiedzi lub dane binarne z handlera trasy.

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

Handler odpowiada na żądanie, wywołując jedną z metod odpowiedzi obiektu `$`. Każda ustawia za Ciebie właściwy `content-type`.

| Metoda | Wysyła |
|---|---|
| `$.json(value)` | JSON |
| `$.html(string)` | HTML |
| `$.plain(string)` | zwykły tekst |
| `$.xml(string)` | XML |
| `$.redirect(url, [permanent])` | przekierowanie (302, lub 301, gdy `permanent` ma wartość true) |
| `$.empty()` | pustą odpowiedź (status 204) |
| `$.binary(buffer, type)` | dane binarne o podanym 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'));
};
```
