Skip to content
This repository has been archived by the owner on Dec 20, 2020. It is now read-only.

Commit

Permalink
Add a setDefaultDataType() method
Browse files Browse the repository at this point in the history
  • Loading branch information
pyrsmk committed Nov 10, 2015
1 parent 1f6d237 commit 0ca9eb7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
tests/node_modules/
tests/node_modules/
tests/**/Thumbs.db
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ The available `options` are :
- attempts : the total number of times to attempt the request through timeouts; 1 by default; if you want to remove the limit set it to `null`
- pinkyswear : override promise methods (experimental)

You can change the default data type with :

```js
qwest.setDefaultDataType('json');
```

If you want to make a call with another HTTP method, you can use the `map()` function :

```js
Expand Down
11 changes: 7 additions & 4 deletions src/qwest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! qwest 2.2.2 (https://github.com/pyrsmk/qwest) */
/*! qwest 2.2.3 (https://github.com/pyrsmk/qwest) */

module.exports = function() {

Expand All @@ -7,6 +7,8 @@ module.exports = function() {
jparam = require('jquery-param'),
// Default response type for XDR in auto mode
defaultXdrResponseType = 'json',
// Default data type
defaultDataType = 'post',
// Variables for limit mechanism
limit = null,
requests = 0,
Expand Down Expand Up @@ -274,7 +276,7 @@ module.exports = function() {
// Normalize options
options.async = 'async' in options?!!options.async:true;
options.cache = 'cache' in options?!!options.cache:false;
options.dataType = 'dataType' in options?options.dataType.toLowerCase():'post';
options.dataType = 'dataType' in options?options.dataType.toLowerCase():defaultDataType;
options.responseType = 'responseType' in options?options.responseType.toLowerCase():'auto';
options.user = options.user || '';
options.password = options.password || '';
Expand Down Expand Up @@ -370,13 +372,14 @@ module.exports = function() {
return qwest(type.toUpperCase(), this.base+url, data, options, before);
},
xhr2: xhr2,
// obsolete
limit: function(by) {
limit = by;
},
// obsolete
setDefaultXdrResponseType: function(type) {
defaultXdrResponseType = type.toLowerCase();
},
setDefaultDataType: function(type) {
defaultDataType = type.toLowerCase();
}
};

Expand Down

0 comments on commit 0ca9eb7

Please sign in to comment.