Comparing version 1.1.3 to 1.1.4
{ | ||
"name": "uhttp", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"main": "src/uhttp.js", | ||
@@ -5,0 +5,0 @@ "ignore": [ |
{ | ||
"name": "uhttp", | ||
"description": "A micro ajax http library with a unified api for browsers and nodejs", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"repository": "https://github.com/Flux159/uhttp", | ||
@@ -6,0 +6,0 @@ "homepage": "http://flux159.github.io/uhttp/", |
@@ -13,5 +13,7 @@ # uhttp | ||
###### Browser | ||
Download the minified build [here](https://raw.githubusercontent.com/Flux159/uhttp/master/dist/uhttp.min.js), put into your public scripts directory, and add to your webpage by adding the following tag: | ||
``` | ||
```html | ||
<script type="application/javascript" src="/scripts/uhttp.min.js"></script> | ||
@@ -21,8 +23,10 @@ ``` | ||
Alternatively, you can install from bower as well: | ||
``` | ||
```shell | ||
bower install uhttp --save | ||
``` | ||
###### Nodejs | ||
To install with nodejs, run the following: | ||
``` | ||
```shell | ||
npm install uhttp --save | ||
@@ -36,4 +40,6 @@ ``` | ||
Note: You should not use the minified browser version of uhttp in nodejs (or vice versa). This is because while uhttp provides a common api for ajax/http requests, the implementations are different for nodejs and the browser (nodejs uses http.request while browsers use XMLHttpRequest - among other differences). | ||
#### uhttp.get(url, [,options]) | ||
Use uhttp.get() to make a GET request. You can use either "then... catch" callbacks to obtain the response. | ||
Use uhttp.get() to make a GET request. You can use "then... catch" callbacks to obtain the response. | ||
@@ -121,3 +127,3 @@ ```javascript | ||
var myCustomData = '<custom>xml</custom>'; | ||
uhttp.post('/api/endpoint/post', {'Content-Type': 'application/xml'}, myCustomData).then(function(res, status, xhr) { | ||
uhttp.post('/api/endpoint/post', {headers: {'Content-Type': 'application/xml'}}, myCustomData).then(function(res, status, xhr) { | ||
//Success | ||
@@ -180,8 +186,8 @@ }).catch(function(err, status, xhr) { | ||
Use uhttp.jsonp() to send a JSONP request. Note that you should define the callback as 'JSON_CALLBACK'. uhttp will generate a global function attached to the window object for the duration of the request and pass its data to the then/catch functions. | ||
Use uhttp.jsonp() to send a JSONP request. Note that you should define the callback as 'JSON_CALLBACK'. uhttp will generate a global function attached to the window object for the duration of the request and pass its data to the then/catch functions. Note that since [jsonp](http://en.wikipedia.org/wiki/JSONP) requests use a script element and not xhr, there is no status or xhr returned in the callback. | ||
```javascript | ||
uhttp.jsonp('/api/endpoint/jsonp?callback=JSON_CALLBACK').then(function(res, status, xhr) { | ||
uhttp.jsonp('/api/endpoint/jsonp?callback=JSON_CALLBACK').then(function(res) { | ||
//Success | ||
}).catch(function(res, status, xhr) { | ||
}).catch(function(err) { | ||
//Error | ||
@@ -200,3 +206,3 @@ }); | ||
uhttp.setGlobalOptions = globalOptions; | ||
uhttp.setGlobalOptions(globalOptions); | ||
@@ -212,3 +218,3 @@ uhttp.get('/xsrf/endpoint').then(function(res) { | ||
#### Example: Sending a file | ||
A common use case for POSTing data is to send a file to your server (like an image or video file). uhttp makes that easy by allowing you to specify a progress callback with your POST request. Note that this example uses Xhr2, which is not supported by IE8. Check [caniuse](http://caniuse.com/#feat=xhr2) for more information on browser compatibility. For a full example, see the example in /test/testupload.html | ||
A common use case for POSTing data is to send a file to your server (like an image or video file). uhttp makes that easy by allowing you to specify a progress callback with your POST request. Note that this example uses Xhr2, which is not supported by IE8. Check [caniuse](http://caniuse.com/#feat=xhr2) for more information on browser compatibility. For a full example, see the example in /test/testupload.html. Note that this example will only work in browsers (nodejs does not support FormData objects, however, it may be possible to use [this](https://github.com/felixge/node-form-data) library - this has not been tested w/ uhttp however). | ||
@@ -301,3 +307,3 @@ ```javascript | ||
withCredentials: true, //Set withCredentials on xhr requests, | ||
transformRequest: function(xhr) {}, //Transform xhr before sending (also before transformRequestData) | ||
transformRequest: function(config) {}, //Transform xhr config before sending (also before transformRequestData) | ||
transformResponse: function(xhr) {}, //Transform xhr after response (but before transformResponseData) | ||
@@ -475,2 +481,4 @@ transformRequestData: function(data) {return data;}, //Transform requests before sending | ||
Note that passing uhttp a cache object will only cache get requests. This is because it isn't meaningful to cache POST, PUT, DELETE requests (read [this](http://stackoverflow.com/questions/626057/is-it-possible-to-cache-post-methods-in-http) for more information). | ||
###### Cookies Helpers | ||
@@ -489,3 +497,3 @@ | ||
uhttp is developed using a nodejs environment. Make sure that you have nodejs and npm installed, clone this source repository and run the following in the uhttp directory: | ||
uhttp is developed using a nodejs environment and uses [grunt](http://gruntjs.com/getting-started) for running tests and building. Make sure that you have nodejs and npm installed, clone this source repository and run the following in the uhttp directory: | ||
@@ -492,0 +500,0 @@ ``` |
@@ -7,4 +7,4 @@ /** | ||
define(factory); | ||
} else if (typeof 'exports' === 'object') { | ||
module.exports = factory; | ||
} else if (typeof module !== 'undefined') { | ||
module.exports = factory(); | ||
} else { | ||
@@ -11,0 +11,0 @@ root.uhttp = factory(root); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
105511
522