ForgeTotal.js 5
hu

Total.js 5

Minden HTTP-metódus kezelése

Total.js 5 · total5@0.0.19 routinghttp Total.js 5-tel lefuttatva

Egy útvonal első szava a HTTP-metódus: GET, POST, PUT, PATCH, DELETE. Ugyanahhoz az URL-hez metódusonként más handler tartozhat, a $.method pedig megmondja egy közös handlernek, melyiket használták.

controllers/items.js
exports.install = function() {
	ROUTE('GET /items/', list);
	ROUTE('POST /items/', create);
	ROUTE('PUT /items/', replace);
	ROUTE('PATCH /items/', change);
	ROUTE('DELETE /items/', remove);
};

function list($) {
	$.json({ action: 'list', method: $.method });
}

function create($) {
	$.json({ action: 'create', method: $.method });
}

function replace($) {
	$.json({ action: 'replace', method: $.method });
}

function change($) {
	$.json({ action: 'change', method: $.method });
}

function remove($) {
	$.json({ action: 'remove', method: $.method });
}