MockHttpBackend class
A mock implementation of HttpBackend, used in tests.
class MockHttpBackend implements HttpBackend { var definitions = [], expectations = [], responses = []; /** * This function is called from [Http] and designed to mimic the Dart APIs. */ Future request(String url, {String method, bool withCredentials, String responseType, String mimeType, Map<String, String> requestHeaders, sendData, void onProgress(ProgressEvent e)}) { Completer c = new Completer(); var callback = (status, data, headers) { if (status >= 200 && status < 300) { c.complete(new MockHttpRequest(status, data, headers)); } else { c.completeError( new MockProgressEvent( new MockHttpRequest(status, data, headers))); } }; call(method == null ? 'GET' : method, url, sendData, callback, requestHeaders); return c.future; } _createResponse(status, data, headers) { if (status is Function) return status; return ([a,b,c,d,e]) { return status is num ? [status, data, headers] : [200, status, data]; }; } /** * A callback oriented API. This function takes a callback with * will be called with (status, data, headers) */ call(method, [url, data, callback, headers, timeout]) { var xhr = new _MockXhr(), expectation = expectations.isEmpty ? null : expectations[0], wasExpected = false; var prettyPrint = (data) { return (data is String || data is Function || data is RegExp) ? data : json.stringify(data); }; var wrapResponse = (wrapped) { var handleResponse = () { var response = wrapped.response(method, url, data, headers); xhr.$$respHeaders = response[2]; utils.relaxFnApply(callback, [response[0], response[1], xhr.getAllResponseHeaders()]); }; var handleTimeout = () { for (var i = 0, ii = responses.length; i < ii; i++) { if (identical(responses[i], handleResponse)) { responses.removeAt(i); callback(-1, null, ''); break; } } }; if (timeout != null) timeout.then(handleTimeout); return handleResponse; }; if (expectation != null && expectation.match(method, url)) { if (!expectation.matchData(data)) throw ['Expected $expectation with different data\n' + 'EXPECTED: ${prettyPrint(expectation.data)}\nGOT: $data']; if (!expectation.matchHeaders(headers)) throw ['Expected $expectation with different headers\n' + 'EXPECTED: ${prettyPrint(expectation.headers)}\nGOT: ${prettyPrint(headers)}']; expectations.removeAt(0); if (expectation.response != null) { responses.add(wrapResponse(expectation)); return; } wasExpected = true; } for (var definition in definitions) { if (definition.match(method, url, data, headers != null ? headers : {})) { if (definition.response != null) { // if $browser specified, we do auto flush all requests responses.add(wrapResponse(definition)); } else throw ['No response defined !']; return; } } throw wasExpected ? ['No response defined !'] : ['Unexpected request: $method $url\n' + (expectation != null ? 'Expected $expectation' : 'No more requests expected')]; } /** * Creates a new backend definition. * * @param {string} method HTTP method. * @param {string|RegExp} url HTTP url. * @param {(string|RegExp)=} data HTTP request body. * @param {(Object|function(Object))=} headers HTTP headers or function that receives http header * object and returns true if the headers match the current definition. * @returns {requestHandler} Returns an object with `respond` method that control how a matched * request is handled. * * - respond – `{function([status,] data[, headers])|function(function(method, url, data, headers)}` * – The respond method takes a set of static data to be returned or a function that can return * an array containing response status (number), response data (string) and response headers * (Object). */ when(method, [url, data, headers]) { var definition = new MockHttpExpectation(method, url, data, headers), chain = new _Chain(respond: (status, data, headers) { definition.response = _createResponse(status, data, headers); }); definitions.add(definition); return chain; } /** * @ngdoc method * @name ngMock.$httpBackend#whenGET * @methodOf ngMock.$httpBackend * @description * Creates a new backend definition for GET requests. For more info see `when()`. * * @param {string|RegExp} url HTTP url. * @param {(Object|function(Object))=} headers HTTP headers. * @returns {requestHandler} Returns an object with `respond` method that control how a matched * request is handled. */ whenGET(url, [headers]) => when('GET', url, null, headers); whenDELETE(url, [headers]) => when('DELETE', url, null, headers); whenJSONP(url, [headers]) => when('JSONP', url, null, headers); whenPUT(url, [data, headers]) => when('PUT', url, data, headers); whenPOST(url, [data, headers]) => when('POST', url, data, headers); whenPATCH(url, [data, headers]) => when('PATCH', url, data, headers); /** * @ngdoc method * @name ngMock.$httpBackend#whenHEAD * @methodOf ngMock.$httpBackend * @description * Creates a new backend definition for HEAD requests. For more info see `when()`. * * @param {string|RegExp} url HTTP url. * @param {(Object|function(Object))=} headers HTTP headers. * @returns {requestHandler} Returns an object with `respond` method that control how a matched * request is handled. */ /** * @ngdoc method * @name ngMock.$httpBackend#whenDELETE * @methodOf ngMock.$httpBackend * @description * Creates a new backend definition for DELETE requests. For more info see `when()`. * * @param {string|RegExp} url HTTP url. * @param {(Object|function(Object))=} headers HTTP headers. * @returns {requestHandler} Returns an object with `respond` method that control how a matched * request is handled. */ /** * @ngdoc method * @name ngMock.$httpBackend#whenPOST * @methodOf ngMock.$httpBackend * @description * Creates a new backend definition for POST requests. For more info see `when()`. * * @param {string|RegExp} url HTTP url. * @param {(string|RegExp)=} data HTTP request body. * @param {(Object|function(Object))=} headers HTTP headers. * @returns {requestHandler} Returns an object with `respond` method that control how a matched * request is handled. */ /** * @ngdoc method * @name ngMock.$httpBackend#whenPUT * @methodOf ngMock.$httpBackend * @description * Creates a new backend definition for PUT requests. For more info see `when()`. * * @param {string|RegExp} url HTTP url. * @param {(string|RegExp)=} data HTTP request body. * @param {(Object|function(Object))=} headers HTTP headers. * @returns {requestHandler} Returns an object with `respond` method that control how a matched * request is handled. */ /** * @ngdoc method * @name ngMock.$httpBackend#whenJSONP * @methodOf ngMock.$httpBackend * @description * Creates a new backend definition for JSONP requests. For more info see `when()`. * * @param {string|RegExp} url HTTP url. * @returns {requestHandler} Returns an object with `respond` method that control how a matched * request is handled. */ //createShortMethods('when'); /** * @ngdoc method * @name ngMock.$httpBackend#expect * @methodOf ngMock.$httpBackend * @description * Creates a new request expectation. * * @param {string} method HTTP method. * @param {string|RegExp} url HTTP url. * @param {(string|RegExp)=} data HTTP request body. * @param {(Object|function(Object))=} headers HTTP headers or function that receives http header * object and returns true if the headers match the current expectation. * @returns {requestHandler} Returns an object with `respond` method that control how a matched * request is handled. * * - respond – `{function([status,] data[, headers])|function(function(method, url, data, headers)}` * – The respond method takes a set of static data to be returned or a function that can return * an array containing response status (number), response data (string) and response headers * (Object). */ expect(method, [url, data, headers]) { var expectation = new MockHttpExpectation(method, url, data, headers); expectations.add(expectation); return new _Chain(respond: (status, data, headers) { expectation.response = _createResponse(status, data, headers); }); } /** * @ngdoc method * @name ngMock.$httpBackend#expectGET * @methodOf ngMock.$httpBackend * @description * Creates a new request expectation for GET requests. For more info see `expect()`. * * @param {string|RegExp} url HTTP url. * @param {Object=} headers HTTP headers. * @returns {requestHandler} Returns an object with `respond` method that control how a matched * request is handled. See #expect for more info. */ expectGET(url, [headers]) => expect('GET', url, null, headers); expectDELETE(url, [headers]) => expect('DELETE', url, null, headers); expectJSONP(url, [headers]) => expect('JSONP', url, null, headers); expectPUT(url, [data, headers]) => expect('PUT', url, data, headers); expectPOST(url, [data, headers]) => expect('POST', url, data, headers); expectPATCH(url, [data, headers]) => expect('PATCH', url, data, headers); /** * @ngdoc method * @name ngMock.$httpBackend#expectHEAD * @methodOf ngMock.$httpBackend * @description * Creates a new request expectation for HEAD requests. For more info see `expect()`. * * @param {string|RegExp} url HTTP url. * @param {Object=} headers HTTP headers. * @returns {requestHandler} Returns an object with `respond` method that control how a matched * request is handled. */ /** * @ngdoc method * @name ngMock.$httpBackend#expectDELETE * @methodOf ngMock.$httpBackend * @description * Creates a new request expectation for DELETE requests. For more info see `expect()`. * * @param {string|RegExp} url HTTP url. * @param {Object=} headers HTTP headers. * @returns {requestHandler} Returns an object with `respond` method that control how a matched * request is handled. */ /** * @ngdoc method * @name ngMock.$httpBackend#expectPOST * @methodOf ngMock.$httpBackend * @description * Creates a new request expectation for POST requests. For more info see `expect()`. * * @param {string|RegExp} url HTTP url. * @param {(string|RegExp)=} data HTTP request body. * @param {Object=} headers HTTP headers. * @returns {requestHandler} Returns an object with `respond` method that control how a matched * request is handled. */ /** * @ngdoc method * @name ngMock.$httpBackend#expectPUT * @methodOf ngMock.$httpBackend * @description * Creates a new request expectation for PUT requests. For more info see `expect()`. * * @param {string|RegExp} url HTTP url. * @param {(string|RegExp)=} data HTTP request body. * @param {Object=} headers HTTP headers. * @returns {requestHandler} Returns an object with `respond` method that control how a matched * request is handled. */ /** * @ngdoc method * @name ngMock.$httpBackend#expectPATCH * @methodOf ngMock.$httpBackend * @description * Creates a new request expectation for PATCH requests. For more info see `expect()`. * * @param {string|RegExp} url HTTP url. * @param {(string|RegExp)=} data HTTP request body. * @param {Object=} headers HTTP headers. * @returns {requestHandler} Returns an object with `respond` method that control how a matched * request is handled. */ /** * @ngdoc method * @name ngMock.$httpBackend#expectJSONP * @methodOf ngMock.$httpBackend * @description * Creates a new request expectation for JSONP requests. For more info see `expect()`. * * @param {string|RegExp} url HTTP url. * @returns {requestHandler} Returns an object with `respond` method that control how a matched * request is handled. */ //createShortMethods('expect'); /** * @ngdoc method * @name ngMock.$httpBackend#flush * @methodOf ngMock.$httpBackend * @description * Flushes all pending requests using the trained responses. * * @param {number=} count Number of responses to flush (in the order they arrived). If undefined, * all pending requests will be flushed. If there are no pending requests when the flush method * is called an exception is thrown (as this typically a sign of programming error). */ flush([count]) { if (responses.isEmpty) throw ['No pending request to flush !']; if (count != null) { while (count-- > 0) { if (responses.isEmpty) throw ['No more pending request to flush !']; responses.removeAt(0)(); } } else { while (!responses.isEmpty) { responses.removeAt(0)(); } } verifyNoOutstandingExpectation(); } /** * @ngdoc method * @name ngMock.$httpBackend#verifyNoOutstandingExpectation * @methodOf ngMock.$httpBackend * @description * Verifies that all of the requests defined via the `expect` api were made. If any of the * requests were not made, verifyNoOutstandingExpectation throws an exception. * * Typically, you would call this method following each test case that asserts requests using an * "afterEach" clause. * * <pre> * afterEach($httpBackend.verifyNoOutstandingExpectation); * </pre> */ verifyNoOutstandingExpectation() { if (!expectations.isEmpty) { throw ['Unsatisfied requests: ${expectations.join(', ')}']; } } /** * @ngdoc method * @name ngMock.$httpBackend#verifyNoOutstandingRequest * @methodOf ngMock.$httpBackend * @description * Verifies that there are no outstanding requests that need to be flushed. * * Typically, you would call this method following each test case that asserts requests using an * "afterEach" clause. * * <pre> * afterEach($httpBackend.verifyNoOutstandingRequest); * </pre> */ verifyNoOutstandingRequest() { if (!responses.isEmpty) { throw ['Unflushed requests: ${responses.length}']; } } /** * @ngdoc method * @name ngMock.$httpBackend#resetExpectations * @methodOf ngMock.$httpBackend * @description * Resets all request expectations, but preserves all backend definitions. Typically, you would * call resetExpectations during a multiple-phase test when you want to reuse the same instance of * $httpBackend mock. */ resetExpectations() { expectations.length = 0; responses.length = 0; } }
Implements
Properties
var definitions #
var definitions = []
var expectations #
var definitions = [], expectations = []
var responses #
var definitions = [], expectations = [], responses = []
Methods
dynamic call(method, [url, data, callback, headers, timeout]) #
A callback oriented API. This function takes a callback with will be called with (status, data, headers)
call(method, [url, data, callback, headers, timeout]) { var xhr = new _MockXhr(), expectation = expectations.isEmpty ? null : expectations[0], wasExpected = false; var prettyPrint = (data) { return (data is String || data is Function || data is RegExp) ? data : json.stringify(data); }; var wrapResponse = (wrapped) { var handleResponse = () { var response = wrapped.response(method, url, data, headers); xhr.$$respHeaders = response[2]; utils.relaxFnApply(callback, [response[0], response[1], xhr.getAllResponseHeaders()]); }; var handleTimeout = () { for (var i = 0, ii = responses.length; i < ii; i++) { if (identical(responses[i], handleResponse)) { responses.removeAt(i); callback(-1, null, ''); break; } } }; if (timeout != null) timeout.then(handleTimeout); return handleResponse; }; if (expectation != null && expectation.match(method, url)) { if (!expectation.matchData(data)) throw ['Expected $expectation with different data\n' + 'EXPECTED: ${prettyPrint(expectation.data)}\nGOT: $data']; if (!expectation.matchHeaders(headers)) throw ['Expected $expectation with different headers\n' + 'EXPECTED: ${prettyPrint(expectation.headers)}\nGOT: ${prettyPrint(headers)}']; expectations.removeAt(0); if (expectation.response != null) { responses.add(wrapResponse(expectation)); return; } wasExpected = true; } for (var definition in definitions) { if (definition.match(method, url, data, headers != null ? headers : {})) { if (definition.response != null) { // if $browser specified, we do auto flush all requests responses.add(wrapResponse(definition)); } else throw ['No response defined !']; return; } } throw wasExpected ? ['No response defined !'] : ['Unexpected request: $method $url\n' + (expectation != null ? 'Expected $expectation' : 'No more requests expected')]; }
dynamic expect(method, [url, data, headers]) #
@ngdoc method
@name ngMock.$httpBackend#whenHEAD
@methodOf ngMock.$httpBackend
@description
Creates a new backend definition for HEAD requests. For more info see when()
.
@param {string|RegExp} url HTTP url.
@param {(Object|function(Object))=} headers HTTP headers.
@returns {requestHandler} Returns an object with respond
method that control how a matched
request is handled.
@ngdoc method
@name ngMock.$httpBackend#whenDELETE
@methodOf ngMock.$httpBackend
@description
Creates a new backend definition for DELETE requests. For more info see when()
.
@param {string|RegExp} url HTTP url.
@param {(Object|function(Object))=} headers HTTP headers.
@returns {requestHandler} Returns an object with respond
method that control how a matched
request is handled.
@ngdoc method
@name ngMock.$httpBackend#whenPOST
@methodOf ngMock.$httpBackend
@description
Creates a new backend definition for POST requests. For more info see when()
.
@param {string|RegExp} url HTTP url.
@param {(string|RegExp)=} data HTTP request body.
@param {(Object|function(Object))=} headers HTTP headers.
@returns {requestHandler} Returns an object with respond
method that control how a matched
request is handled.
@ngdoc method
@name ngMock.$httpBackend#whenPUT
@methodOf ngMock.$httpBackend
@description
Creates a new backend definition for PUT requests. For more info see when()
.
@param {string|RegExp} url HTTP url.
@param {(string|RegExp)=} data HTTP request body.
@param {(Object|function(Object))=} headers HTTP headers.
@returns {requestHandler} Returns an object with respond
method that control how a matched
request is handled.
@ngdoc method
@name ngMock.$httpBackend#whenJSONP
@methodOf ngMock.$httpBackend
@description
Creates a new backend definition for JSONP requests. For more info see when()
.
@param {string|RegExp} url HTTP url.
@returns {requestHandler} Returns an object with respond
method that control how a matched
request is handled.
@ngdoc method @name ngMock.$httpBackend#expect @methodOf ngMock.$httpBackend @description Creates a new request expectation.
@param {string} method HTTP method.
@param {string|RegExp} url HTTP url.
@param {(string|RegExp)=} data HTTP request body.
@param {(Object|function(Object))=} headers HTTP headers or function that receives http header
object and returns true if the headers match the current expectation.
@returns {requestHandler} Returns an object with respond
method that control how a matched
request is handled.
-
respond –
{function([status,] data[, headers])|function(function(method, url, data, headers)}
– The respond method takes a set of static data to be returned or a function that can return an array containing response status (number), response data (string) and response headers (Object).
expect(method, [url, data, headers]) { var expectation = new MockHttpExpectation(method, url, data, headers); expectations.add(expectation); return new _Chain(respond: (status, data, headers) { expectation.response = _createResponse(status, data, headers); }); }
dynamic expectDELETE(url, [headers]) #
expectDELETE(url, [headers]) => expect('DELETE', url, null, headers);
dynamic expectGET(url, [headers]) #
@ngdoc method
@name ngMock.$httpBackend#expectGET
@methodOf ngMock.$httpBackend
@description
Creates a new request expectation for GET requests. For more info see expect()
.
@param {string|RegExp} url HTTP url.
@param {Object=} headers HTTP headers.
@returns {requestHandler} Returns an object with respond
method that control how a matched
request is handled. See #expect for more info.
expectGET(url, [headers]) => expect('GET', url, null, headers);
dynamic expectJSONP(url, [headers]) #
expectJSONP(url, [headers]) => expect('JSONP', url, null, headers);
dynamic expectPATCH(url, [data, headers]) #
expectPATCH(url, [data, headers]) => expect('PATCH', url, data, headers);
dynamic expectPOST(url, [data, headers]) #
expectPOST(url, [data, headers]) => expect('POST', url, data, headers);
dynamic expectPUT(url, [data, headers]) #
expectPUT(url, [data, headers]) => expect('PUT', url, data, headers);
dynamic flush([count]) #
@ngdoc method
@name ngMock.$httpBackend#expectHEAD
@methodOf ngMock.$httpBackend
@description
Creates a new request expectation for HEAD requests. For more info see expect()
.
@param {string|RegExp} url HTTP url.
@param {Object=} headers HTTP headers.
@returns {requestHandler} Returns an object with respond
method that control how a matched
request is handled.
@ngdoc method
@name ngMock.$httpBackend#expectDELETE
@methodOf ngMock.$httpBackend
@description
Creates a new request expectation for DELETE requests. For more info see expect()
.
@param {string|RegExp} url HTTP url.
@param {Object=} headers HTTP headers.
@returns {requestHandler} Returns an object with respond
method that control how a matched
request is handled.
@ngdoc method
@name ngMock.$httpBackend#expectPOST
@methodOf ngMock.$httpBackend
@description
Creates a new request expectation for POST requests. For more info see expect()
.
@param {string|RegExp} url HTTP url.
@param {(string|RegExp)=} data HTTP request body.
@param {Object=} headers HTTP headers.
@returns {requestHandler} Returns an object with respond
method that control how a matched
request is handled.
@ngdoc method
@name ngMock.$httpBackend#expectPUT
@methodOf ngMock.$httpBackend
@description
Creates a new request expectation for PUT requests. For more info see expect()
.
@param {string|RegExp} url HTTP url.
@param {(string|RegExp)=} data HTTP request body.
@param {Object=} headers HTTP headers.
@returns {requestHandler} Returns an object with respond
method that control how a matched
request is handled.
@ngdoc method
@name ngMock.$httpBackend#expectPATCH
@methodOf ngMock.$httpBackend
@description
Creates a new request expectation for PATCH requests. For more info see expect()
.
@param {string|RegExp} url HTTP url.
@param {(string|RegExp)=} data HTTP request body.
@param {Object=} headers HTTP headers.
@returns {requestHandler} Returns an object with respond
method that control how a matched
request is handled.
@ngdoc method
@name ngMock.$httpBackend#expectJSONP
@methodOf ngMock.$httpBackend
@description
Creates a new request expectation for JSONP requests. For more info see expect()
.
@param {string|RegExp} url HTTP url.
@returns {requestHandler} Returns an object with respond
method that control how a matched
request is handled.
@ngdoc method @name ngMock.$httpBackend#flush @methodOf ngMock.$httpBackend @description Flushes all pending requests using the trained responses.
@param {number=} count Number of responses to flush (in the order they arrived). If undefined, all pending requests will be flushed. If there are no pending requests when the flush method is called an exception is thrown (as this typically a sign of programming error).
flush([count]) { if (responses.isEmpty) throw ['No pending request to flush !']; if (count != null) { while (count-- > 0) { if (responses.isEmpty) throw ['No more pending request to flush !']; responses.removeAt(0)(); } } else { while (!responses.isEmpty) { responses.removeAt(0)(); } } verifyNoOutstandingExpectation(); }
Future request(String url, {String method, bool withCredentials, String responseType, String mimeType, Map<String, String> requestHeaders, sendData, void onProgress(ProgressEvent e)}) #
This function is called from Http and designed to mimic the Dart APIs.
Future request(String url, {String method, bool withCredentials, String responseType, String mimeType, Map<String, String> requestHeaders, sendData, void onProgress(ProgressEvent e)}) { Completer c = new Completer(); var callback = (status, data, headers) { if (status >= 200 && status < 300) { c.complete(new MockHttpRequest(status, data, headers)); } else { c.completeError( new MockProgressEvent( new MockHttpRequest(status, data, headers))); } }; call(method == null ? 'GET' : method, url, sendData, callback, requestHeaders); return c.future; }
dynamic resetExpectations() #
@ngdoc method @name ngMock.$httpBackend#resetExpectations @methodOf ngMock.$httpBackend @description Resets all request expectations, but preserves all backend definitions. Typically, you would call resetExpectations during a multiple-phase test when you want to reuse the same instance of $httpBackend mock.
resetExpectations() { expectations.length = 0; responses.length = 0; }
dynamic verifyNoOutstandingExpectation() #
@ngdoc method
@name ngMock.$httpBackend#verifyNoOutstandingExpectation
@methodOf ngMock.$httpBackend
@description
Verifies that all of the requests defined via the expect
api were made. If any of the
requests were not made, verifyNoOutstandingExpectation throws an exception.
Typically, you would call this method following each test case that asserts requests using an "afterEach" clause.
afterEach($httpBackend.verifyNoOutstandingExpectation);
verifyNoOutstandingExpectation() { if (!expectations.isEmpty) { throw ['Unsatisfied requests: ${expectations.join(', ')}']; } }
dynamic verifyNoOutstandingRequest() #
@ngdoc method @name ngMock.$httpBackend#verifyNoOutstandingRequest @methodOf ngMock.$httpBackend @description Verifies that there are no outstanding requests that need to be flushed.
Typically, you would call this method following each test case that asserts requests using an "afterEach" clause.
afterEach($httpBackend.verifyNoOutstandingRequest);
verifyNoOutstandingRequest() { if (!responses.isEmpty) { throw ['Unflushed requests: ${responses.length}']; } }
dynamic when(method, [url, data, headers]) #
Creates a new backend definition.
@param {string} method HTTP method.
@param {string|RegExp} url HTTP url.
@param {(string|RegExp)=} data HTTP request body.
@param {(Object|function(Object))=} headers HTTP headers or function that receives http header
object and returns true if the headers match the current definition.
@returns {requestHandler} Returns an object with respond
method that control how a matched
request is handled.
-
respond –
{function([status,] data[, headers])|function(function(method, url, data, headers)}
– The respond method takes a set of static data to be returned or a function that can return an array containing response status (number), response data (string) and response headers (Object).
when(method, [url, data, headers]) { var definition = new MockHttpExpectation(method, url, data, headers), chain = new _Chain(respond: (status, data, headers) { definition.response = _createResponse(status, data, headers); }); definitions.add(definition); return chain; }
dynamic whenDELETE(url, [headers]) #
whenDELETE(url, [headers]) => when('DELETE', url, null, headers);
dynamic whenGET(url, [headers]) #
@ngdoc method
@name ngMock.$httpBackend#whenGET
@methodOf ngMock.$httpBackend
@description
Creates a new backend definition for GET requests. For more info see when()
.
@param {string|RegExp} url HTTP url.
@param {(Object|function(Object))=} headers HTTP headers.
@returns {requestHandler} Returns an object with respond
method that control how a matched
request is handled.
whenGET(url, [headers]) => when('GET', url, null, headers);
dynamic whenJSONP(url, [headers]) #
whenJSONP(url, [headers]) => when('JSONP', url, null, headers);
dynamic whenPATCH(url, [data, headers]) #
whenPATCH(url, [data, headers]) => when('PATCH', url, data, headers);
dynamic whenPOST(url, [data, headers]) #
whenPOST(url, [data, headers]) => when('POST', url, data, headers);
dynamic whenPUT(url, [data, headers]) #
whenPUT(url, [data, headers]) => when('PUT', url, data, headers);