From 33b992dd017be125df7b83f80e5d08e0f5448158 Mon Sep 17 00:00:00 2001 From: Subhash Sharma Date: Thu, 24 Sep 2015 23:24:17 +0530 Subject: [PATCH] corrected fetch args to support Request Corrected fetch function to support Request Object as an alternate argument as defined by MDN documentation for fetch API. --- whatwg-fetch/whatwg-fetch-tests.ts | 11 +++++++++++ whatwg-fetch/whatwg-fetch.d.ts | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/whatwg-fetch/whatwg-fetch-tests.ts b/whatwg-fetch/whatwg-fetch-tests.ts index 5248f5d1d..f2e2bce11 100644 --- a/whatwg-fetch/whatwg-fetch-tests.ts +++ b/whatwg-fetch/whatwg-fetch-tests.ts @@ -25,6 +25,17 @@ function test_fetchUrl() { handlePromise(window.fetch("http://www.andlabs.net/html5/uCOR.php")); } +function test_fetchUrlWithRequestObject() { + var requestOptions: RequestInit = { + method: "POST", + headers: { + 'Content-Type': 'application/json' + } + }; + var request: Request = new Request("http://www.andlabs.net/html5/uCOR.php", requestOptions); + handlePromise(window.fetch(request)); +} + function handlePromise(promise: Promise) { promise.then((response) => { return response.text(); diff --git a/whatwg-fetch/whatwg-fetch.d.ts b/whatwg-fetch/whatwg-fetch.d.ts index 9efd039b4..a39d204a2 100644 --- a/whatwg-fetch/whatwg-fetch.d.ts +++ b/whatwg-fetch/whatwg-fetch.d.ts @@ -80,5 +80,5 @@ declare type BodyInit = Blob|FormData|string; declare type RequestInfo = Request|string; interface Window { - fetch(url: string, init?: RequestInit): Promise; + fetch(url: string|Request, init?: RequestInit): Promise; }