Last active
August 29, 2015 14:22
-
-
Save luqmaan/9bd6836d9cf37e33efcf to your computer and use it in GitHub Desktop.
Use request/request and when.js together
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import when from 'when'; | |
import rw from './request-when'; | |
return rw({ | |
uri: '/howdy', | |
method: 'get', | |
}) | |
.tap((body) => console.log('hai', body)) | |
.catch((err) => console.error(err)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import request from 'request'; | |
import when from 'when'; | |
export default function ajax(options) { | |
var deferred = when.defer(); | |
options.baseUrl = location.origin || location.protocol + "//" + location.host; | |
options.json = true; | |
request(options, (err, res, body) => { | |
if (err) { | |
console.error(err); | |
return deferred.reject(err); | |
} | |
return deferred.resolve(body); | |
}); | |
return deferred.promise; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment