ForgeTotal.js 5
fr

Total.js 5

Choisir comment répondre

Total.js 5 · total5@0.0.19 routingresponse Exécutée avec Total.js 5

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éthodeEnvoie
$.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é
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'));
};