Created
April 6, 2010 09:11
-
-
Save oberhamsi/357388 to your computer and use it in GitHub Desktop.
This file contains 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
var {get, post, request, HttpClient} = require('ringo/httpclient'); | |
// Exchange holds all information regarding request and response. | |
// All the callbacks get it and it's returned by every shortcut function. | |
var exchange = get('http://example.org', | |
{'paramFoo': 'bar'}, // <- can also be a stream | |
function success (content, status, contentType, exchange){}; | |
function error (exception, httpExchange) | |
); | |
// If you don't like the callbacks you can grab all data from the returned | |
// Exchange | |
print (exchange.status); | |
// you can do async, which makes a lot of sense for streaming: | |
request({ | |
'async': true, | |
'url': 'http://example.org/stream/', | |
'part': function(chunck, status, contentType, httpExchange) { | |
// part gets called repeatedly with the 'chunck' we recieved | |
}, | |
'error':..... | |
}); | |
// use the Client if you make *lots* of requests or want more browser-y behaviour | |
// (auto cookie handling, auto redirects) | |
var client = HttpClient(2000); // timeout in ms | |
client.request... | |
client.post... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment