Class AsyncWebRequest

#include <Geode/utils/web.hpp>
classAsyncWebRequest{ ... }

An asynchronous, thread-safe web request. Downloads data from the internet without slowing the main thread. All callbacks are run in the GD thread, so interacting with the Cocos2d UI is perfectly safe

Examples0
Public static methods0
Public member functions20
geode::utils::web::AsyncWebResponsefetch()

URL to fetch from the internet asynchronously

Parameters

url

URL of the data to download. Redirects will be automatically followed
Return value
An AsyncWebResponse object
geode::utils::web::SentAsyncWebRequestHandlesend()

Begin the web request. It’s not always necessary to call this as the destructor calls it automatically, but if you need access to the handle of the sent request, use this

Return value
Handle to the sent web request
geode::utils::web::AsyncWebResponseget()

Shorthand for a GET request to the given url. Same return value as fetch.

geode::utils::web::AsyncWebResponsepost()

Shorthand for a POST request to the given url. Same return value as fetch.

geode::utils::web::AsyncWebResponseput()

Shorthand for a PUT request to the given url. Same return value as fetch.

geode::utils::web::AsyncWebResponsepatch()

Shorthand for a PATCH request to the given url. Same return value as fetch.

geode::utils::web::AsyncWebRequest&join()

If you only want one instance of this web request to run (for example, you’re downloading some global data for a manager), then use this to specify a Join ID. If another request with the same ID is already running, this request’s callbacks will be appended to the existing one instead of creating a new request

Parameters

requestID

The Join ID of the request. Can be anything, recommended to be something unique
Return value
Same AsyncWebRequest
geode::utils::web::AsyncWebRequest&userAgent()

In order to specify an user agent to the request, give it here.

geode::utils::web::AsyncWebRequest&contentType()

Sets the Content-Type header to the specified value.

geode::utils::web::AsyncWebRequest&postRequest()

Specify that the request is a POST request.

geode::utils::web::AsyncWebRequest&method()

Specify the HTTP method for the request, like PUT and DELETE.

geode::utils::web::AsyncWebRequest&bodyRaw()

Specify the raw request body to send with the request. Content type is unchanged.

geode::utils::web::AsyncWebRequest&body()

Specify a json request body. Additionally sets the content type to application/json.

geode::utils::web::AsyncWebRequest&timeout()

Specify a timeout, in seconds, in which the request will fail.

geode::utils::web::AsyncWebRequest&expect()

Specify a callback to run if the download fails. The callback is always ran in the GD thread, so interacting with UI is safe

Parameters

handler

Callback to run if the download fails
Return value
Same AsyncWebRequest
geode::utils::web::AsyncWebRequest&expect()

Specify a callback to run if the download fails. The callback is always ran in the GD thread, so interacting with UI is safe

Parameters

handler

Callback to run if the download fails
Return value
Same AsyncWebRequest
geode::utils::web::AsyncWebRequest&progress()

Specify a callback to run when the download progresses. The callback is always ran in the GD thread, so interacting with UI is safe

Parameters

handler

Callback to run when the download progresses
Return value
Same AsyncWebRequest
geode::utils::web::AsyncWebRequest&cancelled()

Specify a callback to run if the download is cancelled. The callback is always ran in the GD thread, so interacting with UI is safe. Web requests may be cancelled after they are finished (for example, if downloading files in bulk and one fails). In that case, handle freeing up the results of then in this handler

Parameters

handler

Callback to run if the download is cancelled
Return value
Same AsyncWebRequest
Fields0
Protected member functions0
Protected fields0