|
| 1 | +<p align="center"> |
| 2 | + <img src="https://i.imgur.com/JaXEFNp.png" width="300" height="300" alt="unfetch"> |
| 3 | + <br> |
| 4 | + <a href="https://www.npmjs.org/package/unfetch"><img src="https://img.shields.io/npm/v/unfetch.svg?style=flat" alt="npm"></a> <a href="https://travis-ci.org/developit/unfetch"><img src="https://travis-ci.org/developit/unfetch.svg?branch=master" alt="travis"></a> |
| 5 | +</p> |
| 6 | + |
| 7 | +# unfetch |
| 8 | + |
| 9 | +> Tiny 500b fetch "barely-polyfill" |
| 10 | +
|
| 11 | +- **Tiny:** weighs about **500 bytes** gzipped |
| 12 | +- **Minimal:** just `fetch()` with headers and text/json/xml responses |
| 13 | +- **Familiar:** a subset of the full API |
| 14 | +- **Supported:** supports IE8+ (<abbr title="Bring Your Own Promises">BYOP</abbr>) |
| 15 | +- **Standalone:** one function, no dependencies |
| 16 | + |
| 17 | +> 🤔 **What's Missing?** |
| 18 | +> |
| 19 | +> - Uses simple Arrays instead of Iterables, since Arrays _are_ iterables |
| 20 | +> - No streaming, just Promisifies existing XMLHttpRequest response bodies |
| 21 | +> - Bare-bones `.blob()` implementation - just proxies `xhr.response` |
| 22 | +
|
| 23 | +* * * |
| 24 | + |
| 25 | +## Table of Contents |
| 26 | + |
| 27 | +- [Install](#install) |
| 28 | +- [Usage](#usage) |
| 29 | +- [Examples & Demos](#examples--demos) |
| 30 | +- [API](#api) |
| 31 | +- [Contribute](#contribute) |
| 32 | +- [License](#license) |
| 33 | + |
| 34 | +* * * |
| 35 | + |
| 36 | +## Install |
| 37 | + |
| 38 | +This project uses [node](http://nodejs.org) and [npm](https://npmjs.com). Go check them out if you don't have them locally installed. |
| 39 | + |
| 40 | +```sh |
| 41 | +$ npm install --save unfetch |
| 42 | +``` |
| 43 | + |
| 44 | +Then with a module bundler like [rollup](http://rollupjs.org/) or [webpack](https://webpack.js.org/), use as you would anything else: |
| 45 | + |
| 46 | +```javascript |
| 47 | +// using ES6 modules |
| 48 | +import fetch from 'unfetch' |
| 49 | + |
| 50 | +// using CommonJS modules |
| 51 | +var fetch = require('unfetch') |
| 52 | +``` |
| 53 | + |
| 54 | +The [UMD](https://github.com/umdjs/umd) build is also available on [unpkg](https://unpkg.com): |
| 55 | + |
| 56 | +```html |
| 57 | +<script src="https://unpkg.com/unfetch/dist/unfetch.umd.js"></script> |
| 58 | +``` |
| 59 | + |
| 60 | +This exposes a `fetch` global if not already present. |
| 61 | + |
| 62 | +* * * |
| 63 | + |
| 64 | +## Usage |
| 65 | + |
| 66 | +```js |
| 67 | +import fetch from 'unfetch' |
| 68 | + |
| 69 | +fetch('/foo.json') |
| 70 | + .then( r => r.json() ) |
| 71 | + .then( data => { |
| 72 | + console.log(data) |
| 73 | + }) |
| 74 | +``` |
| 75 | + |
| 76 | +## Examples & Demos |
| 77 | + |
| 78 | +_Coming soon!_ |
| 79 | + |
| 80 | +* * * |
| 81 | + |
| 82 | +## API |
| 83 | + |
| 84 | +## Contribute |
| 85 | + |
| 86 | +First off, thanks for taking the time to contribute! |
| 87 | +Now, take a moment to be sure your contributions make sense to everyone else. |
| 88 | + |
| 89 | +### Reporting Issues |
| 90 | + |
| 91 | +Found a problem? Want a new feature? First of all see if your issue or idea has [already been reported](../../issues). |
| 92 | +If don't, just open a [new clear and descriptive issue](../../issues/new). |
| 93 | + |
| 94 | +### Submitting pull requests |
| 95 | + |
| 96 | +Pull requests are the greatest contributions, so be sure they are focused in scope, and do avoid unrelated commits. |
| 97 | + |
| 98 | +- Fork it! |
| 99 | +- Clone your fork: `git clone https://github.com/<your-username>/unfetch` |
| 100 | +- Navigate to the newly cloned directory: `cd unfetch` |
| 101 | +- Create a new branch for the new feature: `git checkout -b my-new-feature` |
| 102 | +- Install the tools necessary for development: `npm install` |
| 103 | +- Make your changes. |
| 104 | +- Commit your changes: `git commit -am 'Add some feature'` |
| 105 | +- Push to the branch: `git push origin my-new-feature` |
| 106 | +- Submit a pull request with full remarks documenting your changes. |
| 107 | + |
| 108 | +## License |
| 109 | + |
| 110 | +[MIT License](LICENSE.md) © [Jason Miller](https://jasonformat.com/) |
0 commit comments