You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 3 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. isomorphic-fetch [![Build Status](https://travis-ci.org/matthew-andrews/isomorphic-fetch.svg?branch=master)](https://travis-ci.org/matthew-andrews/isomorphic-fetch)
  2. ================
  3. Fetch for node and Browserify. Built on top of [GitHub's WHATWG Fetch polyfill](https://github.com/github/fetch).
  4. ## Warnings
  5. - This adds `fetch` as a global so that its API is consistent between client and server.
  6. - You must bring your own ES6 Promise compatible polyfill, I suggest [es6-promise](https://github.com/jakearchibald/es6-promise).
  7. ## Installation
  8. ### NPM
  9. ```sh
  10. npm install --save isomorphic-fetch es6-promise
  11. ```
  12. ### Bower
  13. ```sh
  14. bower install --save isomorphic-fetch es6-promise
  15. ```
  16. ## Usage
  17. ```js
  18. require('es6-promise').polyfill();
  19. require('isomorphic-fetch');
  20. fetch('//offline-news-api.herokuapp.com/stories')
  21. .then(function(response) {
  22. if (response.status >= 400) {
  23. throw new Error("Bad response from server");
  24. }
  25. return response.json();
  26. })
  27. .then(function(stories) {
  28. console.log(stories);
  29. });
  30. ```
  31. ## License
  32. All open source code released by FT Labs is licenced under the MIT licence. Based on [the fine work by](https://github.com/github/fetch/pull/31) **[jxck](https://github.com/Jxck)**.