fetch
The Fetch API provides an interface for fetching resources (including across the network). It will seem familiar to anyone who has used
XMLHttpRequest
, but the new API provides a more powerful and flexible feature set.
Using in Browsers
Not supported on all browsers. You can polyfill using watchwg-fetch
https://npmcompare.com/compare/node-fetch,whatwg-fetch
Using in Node.js
Importing:
fetch-import-success.ts
If you use webpack, the following will work locally, but fail when deployed in webpack.
fetch-webpack-import-fail.ts
Text:
fetch-text.ts
response
:
fetch-text-response.ts
JSON:
fetch-json.ts
Errors Handling
No errors are thrown.
No need for try/catch
fetch-error.ts
response
:
fetch-error-response.json
Last updated