Last active
July 8, 2018 00:36
-
-
Save MarianoGnu/19dc48a94715ae2cb5a36d78aa6d2d26 to your computer and use it in GitHub Desktop.
usage example at https://gist.github.com/MarianoGnu/8867253ba5df00c87a599745d25aa55c
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
extends HTTPRequest | |
var last_response = null | |
func _ready(): | |
# connect signal to catch body | |
self.connect("request_completed", self, "_on_HTTPRequest_request_completed") | |
func request_url(url): | |
self.request(url) # request to REST API | |
# wait until request finishes, | |
# _on_HTTPRequest_request_completed will be called when this happens too | |
yield(self, "request_completed") | |
# wait an extra frame to be sure last_response is loaded | |
yield(get_tree(), "idle_frame") | |
# return last_response as dictionary or array, depending on response | |
return last_response | |
func _on_HTTPRequest_request_completed( result, response_code, headers, body ): | |
last_response = parse_json(body.get_string_from_utf8()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment