Created
May 5, 2017 15:18
-
-
Save alenstarx/3db478490fc16380c39782a17288a37a to your computer and use it in GitHub Desktop.
GET requests in gjs with libsoup
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
const Lang = imports.lang; | |
const Soup = imports.gi.Soup; | |
let _session = new Soup.SessionAsync(); | |
function GET(url, callback) { | |
let request = Soup.Message.new('GET', url); | |
_session.queue_message(request, Lang.bind(this, | |
function(session, message) { | |
callback(message.status_code, request.response_body.data); | |
} | |
) | |
); | |
} | |
// Standalone script only section | |
const Mainloop = imports.mainloop; | |
GET("http://krakensden.com/", function(status_code, body) { log('request done, body: ' + body); Mainloop.quit(true); }); | |
Mainloop.run(true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment