ForgeTotal.js 5
pl

Total.js 5

Obsługa każdej metody HTTP

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

Pierwsze słowo trasy to metoda HTTP: GET, POST, PUT, PATCH, DELETE. Ten sam URL może mieć inny handler dla każdej metody, a $.method mówi współdzielonemu handlerowi, która została użyta.

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