How do I perform get and post requests from Gdscript in Godot? I am trying to get a map API and use it in the game.
1 Answer
As someone else said, check out the HTTPClient class.
It's nonblocking, so you'll need to check for when it's finished.
A barebones example with no error checking would be the following:
var http = HTTPClient.new()
http.connect("www.myapi.net",80)
var headers=[
"User-Agent: Pirulo/1.0 (Godot)",
"Accept: */*"
]
http.request(HTTPClient.METHOD_GET,"/myendpoint",headers)
if (http.has_response()):
#read through the chunks...
Really, this is just pseudo-code. The docs have a really complete code example. http://docs.godotengine.org/en/latest/tutorials/http_client_class.html