The Godot HTTP Module is a simple GDScript addon aims at simplifying sending HTTP Request using the Godot HTTP Request Node by providing an interface that is more easier to use. It support standard REST API such as GET, POST, PUT, PATCH, and DELETE and can also send the data in a HTML form like format, JSON and even can do multiple file uploads at the same time!
download the entire script and make sure to add these script anywhere inside of your Godot Projects:
- HTTPModule.gd
- HTTPResult.gd
- HTTPUpload.gd
- HTTPUploadMultiple.gd
make sure that the HTTPModule node is added to the scene via the scene editor or trough code
var http_module: HTTPModule = HTTPModule.new()
add_child(http_module)
example usage of sending a GET request
http_module.send("http://localhost:8000", [],
{
"foo" : "Hello",
"bar" : "World",
}
, func(result: HTTPResult):
print("request success")
print(result.body_text)
, func(result: HTTPResult):
print("request failed")
print(result.body_text)
)
example usage of sending a POST request
http_module.send("http://localhost:8000", [],
{
"foo" : "Hello",
"bar" : "World",
}
, func(result: HTTPResult):
print("request success")
print(result.body_text)
, func(result: HTTPResult):
print("request failed")
print(result.body_text)
)
example usage of sending a POST request with files upload (the upload method only send data in POST request)
http_module.upload("http://localhost:8000", [],
{
"files" : HTTPUpload.new("res://icon.svg")
}
, func(result: HTTPResult):
print("request success")
print(result.body_text)
, func(result: HTTPResult):
print("request failed")
print(result.body)
print(result.response_code)
)