traverson
Version:
Hypermedia API/HATEOAS client for Node.js and the browser
33 lines (28 loc) • 972 B
JavaScript
;
var minilog = require('minilog')
, log = minilog('traverson')
, abortTraversal = require('../abort_traversal')
, httpRequests = require('../http_requests');
/*
* Execute the last http request in a traversal that ends in
* post/put/patch/delete and call t.callback immediately when done.
*/
// TODO Why is this different from when do a GET at the end of the traversal?
// Probably only because the HTTP method is configurable here (with
// t.lastMethod), we might be able to unify this with the
// fetch_resource/fetch_last_resource transform.
function executeLastHttpRequest(t, callback) {
// always check for aborted before doing an HTTP request
if (t.aborted) {
return abortTraversal.callCallbackOnAbort(t);
}
httpRequests.executeHttpRequest(
t,
t.requestModuleInstance,
t.lastMethod,
t.lastMethodName,
t.callback
);
}
executeLastHttpRequest.isAsync = true;
module.exports = executeLastHttpRequest;