Χειρισμός κάθε μεθόδου HTTP
Η πρώτη λέξη μιας διαδρομής είναι η μέθοδος HTTP: GET, POST, PUT, PATCH, DELETE. Το ίδιο URL μπορεί να έχει διαφορετικό handler για κάθε μέθοδο, και το $.method λέει σε έναν κοινό handler ποια χρησιμοποιήθηκε.
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 });
}