ForgeTotal.js 5
pl

Total.js 5

Wybór sposobu odpowiedzi

Total.js 5 · total5@0.0.19 routingresponse Uruchomiono z Total.js 5

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

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