Skip to content

Instantly share code, notes, and snippets.

@MarianoGnu
Last active July 8, 2018 00:36
Show Gist options
  • Save MarianoGnu/19dc48a94715ae2cb5a36d78aa6d2d26 to your computer and use it in GitHub Desktop.
Save MarianoGnu/19dc48a94715ae2cb5a36d78aa6d2d26 to your computer and use it in GitHub Desktop.
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