xhr-promise-redux
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "xhr-promise-redux", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "XMLHttpRequest implementation wrapped in a promise.js Promise object", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
105
README.md
@@ -27,54 +27,57 @@ Originally forked from [frikille/promised-xhr](https://github.com/frikille/promised-xhr) | ||
1. Sending a GET request | ||
```javascript | ||
xhr.get('/test-url', { | ||
data: { | ||
param: 'value' | ||
}, | ||
headers: { | ||
'Header-name': 'Header value' | ||
}, | ||
responseType: 'json' | ||
}) | ||
.then(function (response) { | ||
console.log(`Success! The response JSON object: ${response.body}`); | ||
}) | ||
.catch(function(response) { | ||
console.log(`Error! Response Status Code: ${response.statusCode}`) | ||
}); | ||
``` | ||
```javascript | ||
xhr.get('/test-url', { | ||
data: { | ||
param: 'value' | ||
}, | ||
headers: { | ||
'Header-name': 'Header value' | ||
}, | ||
responseType: 'json' | ||
}) | ||
.then(function (response) { | ||
console.log(`Success! The response JSON object: ${response.body}`); | ||
}) | ||
.catch(function(response) { | ||
console.log(`Error! Response Status Code: ${response.statusCode}`) | ||
}); | ||
``` | ||
2. Sending a POST request with JSON | ||
```javascript | ||
xhr.post('/test-url', { | ||
json: { | ||
param: 'value' | ||
}, | ||
headers: { | ||
'Header-name': 'Header value' | ||
}, | ||
responseType: 'json' | ||
}) | ||
.then(function (response) { | ||
console.log(`Success! The response JSON object: ${response.body}`); | ||
}) | ||
.catch(function(response) { | ||
console.log(`Error! Response Status Code: ${response.statusCode}`) | ||
}); | ||
``` | ||
```javascript | ||
xhr.post('/test-url', { | ||
json: { | ||
param: 'value' | ||
}, | ||
headers: { | ||
'Header-name': 'Header value' | ||
}, | ||
responseType: 'json' | ||
}) | ||
.then(function (response) { | ||
console.log(`Success! The response JSON object: ${response.body}`); | ||
}) | ||
.catch(function(response) { | ||
console.log(`Error! Response Status Code: ${response.statusCode}`) | ||
}); | ||
``` | ||
3. Sending a request with any method | ||
```javascript | ||
xhr.send('/test-url', { | ||
method: 'PUT', | ||
json: { | ||
param: 'value' | ||
}, | ||
headers: { | ||
'Header-name': 'Header value' | ||
} | ||
}) | ||
.then(function (response) { | ||
console.log(`Success! The response JSON object: ${response.body}`); | ||
}) | ||
.catch(function(response) { | ||
console.log(`Error! Response Status Code: ${response.statusCode}`) | ||
}); | ||
``` | ||
```javascript | ||
xhr.send('/test-url', { | ||
method: 'PUT', | ||
json: { | ||
param: 'value' | ||
}, | ||
headers: { | ||
'Header-name': 'Header value' | ||
} | ||
}) | ||
.then(function (response) { | ||
console.log(`Success! The response JSON object: ${response.body}`); | ||
}) | ||
.catch(function(response) { | ||
console.log(`Error! Response Status Code: ${response.statusCode}`) | ||
}); | ||
``` |
7738
83