# Scegliere come rispondere

> Invia JSON, HTML, testo semplice, XML, redirect, risposte vuote o dati binari da un handler di route.

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

Un handler risponde alla richiesta chiamando uno dei metodi di risposta di `$`. Ciascuno imposta per te il `content-type` giusto.

| Metodo | Invia |
|---|---|
| `$.json(value)` | JSON |
| `$.html(string)` | HTML |
| `$.plain(string)` | testo semplice |
| `$.xml(string)` | XML |
| `$.redirect(url, [permanent])` | un redirect (302, o 301 quando `permanent` è true) |
| `$.empty()` | una risposta vuota (stato 204) |
| `$.binary(buffer, type)` | dati binari con il content type indicato |

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