wonderful-fetch
Advanced tools
Comparing version 1.1.4 to 1.1.5
@@ -19,2 +19,3 @@ (function (root, factory) { | ||
var jetpack; | ||
var path; | ||
@@ -24,3 +25,3 @@ var environment = (Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]') ? 'node' : 'browser'; | ||
var SOURCE = 'library'; | ||
var VERSION = '1.1.4'; | ||
var VERSION = '1.1.5'; | ||
@@ -27,0 +28,0 @@ function WonderfulFetch(url, options) { |
{ | ||
"name": "wonderful-fetch", | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"description": "A wrapper around fetch.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -32,6 +32,6 @@ <p align="center"> | ||
## Wonderful Fetch Works in Node AND browser environments | ||
## đ Wonderful Fetch Works in Node AND browser environments | ||
Yes, this module works in both Node and browser environments, including compatibility with [Webpack](https://www.npmjs.com/package/webpack) and [Browserify](https://www.npmjs.com/package/browserify)! | ||
## Features | ||
## âĄī¸ Features | ||
* Intuitive error handling | ||
@@ -43,3 +43,25 @@ * Download files directly to drive | ||
## Install Wonderful Fetch | ||
## đĒĻ The old way | ||
You have to manually check if the response is `ok` and then parse the response as JSON. | ||
```js | ||
fetch('https://httpbin.org/json') | ||
.then((response) => { | ||
if (!response.ok) { | ||
throw new Error('Network response was not ok'); | ||
} | ||
return response.json(); | ||
}) | ||
.then((data) => console.log(data)) | ||
.catch((error) => console.error(error)); | ||
``` | ||
## đĻ The Wonderful Fetch way | ||
With Wonderful Fetch, you can automatically parse the response as JSON and handle all http errors with a single line of code. | ||
```js | ||
wonderfulFetch('https://httpbin.org/json', {response: 'json'}) | ||
.then((response) => console.log(response)) | ||
.catch((error) => console.error(error)); | ||
``` | ||
## đĻ Install Wonderful Fetch | ||
### Install via npm | ||
@@ -67,3 +89,3 @@ Install with npm if you plan to use `wonderful-fetch` in a Node project or in the browser. | ||
## Using Wonderful Fetch | ||
## đ Using Wonderful Fetch | ||
After you have followed the install step, you can start using `wonderful-fetch` to make requests to any URL | ||
@@ -102,16 +124,46 @@ | ||
#### Examples | ||
##### Basic Fetch | ||
Perform a basic fetch request. | ||
```js | ||
wonderfulFetch('https://httpbin.org/status/200', {method: 'get'}); | ||
wonderfulFetch('https://httpbin.org/status/200', {method: 'get'}) | ||
.then((response) => console.log(response)) | ||
.catch((error) => console.error(error)); | ||
``` | ||
## Extending Capabilities | ||
##### Basic Fetch JSON | ||
Perform a basic fetch request and return the response as JSON. | ||
```js | ||
wonderfulFetch('https://httpbin.org/status/200', {method: 'get', response: 'json'}) | ||
.then((response) => console.log(response)) | ||
.catch((error) => console.error(error)); | ||
``` | ||
##### Download File | ||
Download a file to the specified `download` path. Node.js only. | ||
```js | ||
wonderfulFetch('https://httpbin.org/image/png', {download: './image.png'}) | ||
.then((response) => console.log(response)) | ||
.catch((error) => console.error(error)); | ||
``` | ||
##### Handle Errors with `catch` | ||
Handle errors with the `catch` method. | ||
```js | ||
wonderfulFetch('https://httpbin.org/status/404', {method: 'get'}) | ||
.then((response) => console.log(response)) | ||
.catch((error) => console.error(error)); | ||
``` | ||
## đ Extending Capabilities | ||
For a more in-depth documentation of this library and the Wonderful Fetch service, please visit the official Wonderful Fetch website. | ||
## What Can Wonderful Fetch do? | ||
## â What Can Wonderful Fetch do? | ||
Wonderful Fetch is a free fetch api that helps you make requests in Node.js or the browser. | ||
## Final Words | ||
## đ Final Words | ||
If you are still having difficulty, we would love for you to post a question to [the Wonderful Fetch issues page](https://github.com/itw-creative-works/wonderful-fetch/issues). It is much easier to answer questions that include your code and relevant files! So if you can provide them, we'd be extremely grateful (and more likely to help you find the answer!) | ||
## Projects Using this Library | ||
## đ Projects Using this Library | ||
[Somiibo](https://somiibo.com/): A Social Media Bot with an open-source module library. <br> | ||
@@ -118,0 +170,0 @@ [JekyllUp](https://jekyllup.com/): A website devoted to sharing the best Jekyll themes. <br> |
18560
234
172