ForgeTotal.js 5
ro

Total.js 5

Alegerea modului de a răspunde

Total.js 5 · total5@0.0.19 routingresponse Executată cu Total.js 5

Un handler răspunde cererii apelând una dintre metodele de răspuns ale lui $. Fiecare setează content-type-ul corect pentru tine.

MetodăTrimite
$.json(value)JSON
$.html(string)HTML
$.plain(string)text simplu
$.xml(string)XML
$.redirect(url, [permanent])o redirecționare (302, sau 301 când permanent este true)
$.empty()un răspuns gol (status 204)
$.binary(buffer, type)date binare cu content type-ul dat
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'));
};