# Elige cómo responder

> Envía JSON, HTML, texto plano, XML, redirecciones, respuestas vacías o datos binarios desde un manejador de ruta.

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

Un manejador responde a la petición llamando a uno de los métodos de respuesta de `$`. Cada uno define el `content-type` correcto por ti.

| Método | Envía |
|---|---|
| `$.json(value)` | JSON |
| `$.html(string)` | HTML |
| `$.plain(string)` | texto plano |
| `$.xml(string)` | XML |
| `$.redirect(url, [permanent])` | una redirección (302, o 301 si `permanent` es true) |
| `$.empty()` | una respuesta vacía (estado 204) |
| `$.binary(buffer, type)` | datos binarios con el content type indicado |

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