- From: Jake Archibald <notifications@github.com>
- Date: Wed, 07 Dec 2016 08:47:18 -0800
- To: whatwg/fetch <fetch@noreply.github.com>
Received on Wednesday, 7 December 2016 16:47:50 UTC
@Galen-Yip I don't think this should be part of the API, but you can do it yourself:
```js
function fetchType(request, type, opts={}) {
if (!['json', 'arrayBuffer', 'blob', 'formData', 'text'].includes(type)) {
return Promise.reject(TypeError('Invalid response type'));
}
return fetch(request, opts).then(r => r[type]());
}
// usage:
fetchType('/', 'json').then(data => …);
```
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/430#issuecomment-265501189
Received on Wednesday, 7 December 2016 16:47:50 UTC