extends Node2D @onready var http_request = $HTTPRequest # var base_address = "https://animegame.eu/api" var base_address = "http://localhost:8000/api" var auth_token = null func create_dojo(dojo_name : String): ## Maybe get the HTTPRequest via parameter? var body = JSON.stringify({"name": dojo_name}) if http_request.get_http_client_status(): # Prevent simultaneous request! push_error("Busy with ongoing transaction!") return # _create_dojo_request.request_completed.connect(self._http_request_completed) var error = http_request.request("{address}/dojos".format({"address": base_address}), ["Content-Type: application/json"], HTTPClient.METHOD_POST, body) if error != OK: push_error("An error occurred in the HTTP request.") else: print("Okay?") print("Amount of children %s" % get_child_count()) # Called when the node enters the scene tree for the first time. func _ready(): pass # Replace with function body. # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(_delta): pass func _on_http_request_request_completed(_result, _response_code, headers, body): ## Where to get the response to? print("Completed?") var json = JSON.new() json.parse(body.get_string_from_utf8()) var response = json.get_data() # Will print the user agent string used by the HTTPRequest node (as recognized by httpbin.org). print(headers) print(response)