ForgeTotal.js 5
pt

Total.js 5

Tratar cada método HTTP

Total.js 5 · total5@0.0.19 routinghttp Executada com o Total.js 5

A primeira palavra de uma rota é o método HTTP: GET, POST, PUT, PATCH, DELETE. O mesmo URL pode ter um handler diferente para cada método, e $.method diz a um handler partilhado qual foi usado.

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