Check out our latest project ✨ OpenChapter.io: free ebooks the way its meant to be 📖

cordot

An asset by Abdera7mane
The page banner background of a mountain and forest
cordot hero image

Quick Information

0 ratings
cordot icon image
Abdera7mane
cordot

Discord API wrapper for Godot Engine. It provides a simple interface to build Discord application such as bots. It also comes with a standalone REST client with an option for a stateless mode.

Supported Engine Version
3.5
Version String
0.2.0
License Version
MIT
Support Level
community
Modified Date
2 years ago
Git URL
Issue URL

Simple HTTP Client

Mostly inspired from HTTPRequest node's implementation, brings extra features and improvements. (WIP)

Why not just use HTTPRequest node ?

While I understand that HTTPRequest requires the SceneTree loop to function which is why it is in a form of a Node, there are several reasons to avoid it:

  1. It does not reuse HTTPClient between requests.
  2. It closes and opens a new connection for each redirection even if the redirect host:port is the same.
  3. No way of keeping an alive connection.
  4. Do not use Node for everything.

Ok cool, but shouldn't some of these be reported to Godot's issue tracker ? Yes, I agree however I am not interested in using HTTPRequest in most cases, or at least until it gets a replacement with a more elegant implementation.

Features

  1. Keep-Alive connections, which reduces the overhead when sending requests to the same server.
  2. HTTP connection pool, to send multiple requests by reusing pre-instantiated clients.
  3. Automatic gzip decompression.
  4. Idle connection timeout.
  5. Download streaming.

Examples

HTTP GET method:

var client := SimpleHTTPClient.new()

var url := "https://httpbin.org/headers"
var validate_ssl := true
var method := HTTPClient.METHOD_GET
var headers := {
    "Name": "Value"
}

var response: HTTPResponse = yield(client.request_async(url, headers, validate_ssl, method), "completed")

if response.successful():
    print(response.body.get_string_from_utf8())

if you are willing to reuse the same client to request to the same server, set keep_alive to true, to close the connection call close() (automatically called when the instance is freed)

Streaming:

Requesting large files/payloads must be streamed. The following is an example to download Godot 3.4.4.stable source and save it to a file:

var client := SimpleHTTPClient.new()
client.stream = true

var url: String = "https://downloads.tuxfamily.org/godotengine/3.4.4/godot-3.4.4-stable.tar.xz"

var file := File.new()
if file.open(url.get_file(), File.WRITE) != OK:
    push_error("Failed opening file")
    return

client.request_async(url)

print("Downloading...")

while client.requesting:
    var stream: Array = yield(client, "response_stream")
    var chunk: PoolByteArray = stream[1]
    file.store_buffer(chunk)

print("Completed")

file.close()

Discord API wrapper for Godot Engine. It provides a simple interface to build Discord application such as bots. It also comes with a standalone REST client with an option for a stateless mode.

Reviews

0 ratings

Your Rating

Headline must be at least 3 characters but not more than 50
Review must be at least 5 characters but not more than 500
Please sign in to add a review

Quick Information

0 ratings
cordot icon image
Abdera7mane
cordot

Discord API wrapper for Godot Engine. It provides a simple interface to build Discord application such as bots. It also comes with a standalone REST client with an option for a stateless mode.

Supported Engine Version
3.5
Version String
0.2.0
License Version
MIT
Support Level
community
Modified Date
2 years ago
Git URL
Issue URL

Open Source

Released under the AGPLv3 license

Plug and Play

Browse assets directly from Godot

Community Driven

Created by developers for developers