# Choisir comment répondre

> Envoyez du JSON, du HTML, du texte brut, du XML, des redirections, des réponses vides ou des données binaires depuis un gestionnaire de route.

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

Un gestionnaire répond à la requête en appelant l'une des méthodes de réponse de `$`. Chacune définit le bon `content-type` pour vous.

| Méthode | Envoie |
|---|---|
| `$.json(value)` | du JSON |
| `$.html(string)` | du HTML |
| `$.plain(string)` | du texte brut |
| `$.xml(string)` | du XML |
| `$.redirect(url, [permanent])` | une redirection (302, ou 301 quand `permanent` est true) |
| `$.empty()` | une réponse vide (statut 204) |
| `$.binary(buffer, type)` | des données binaires avec le content type donné |

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