Donut Team is a labor of love, built and maintained by a small group of passionate developers. We invest our own time and resources to offer our tools, mods, and web services completely free of charge.

We don't run ads, and we will never sell your data - period.

If you've enjoyed anything we've created, please consider supporting our work with a one-time or monthly donation via our Ko-fi page . Every contribution helps us continue building great experiences for the community.

Dismiss
  • Modding Tools
  • Simpsons Hit & Run Multiplayer Server
  • Lua API Reference
  • HTTP Functions

HTTP.Request

Available since Version 1.1.

Performs a fully customised HTTP request.

Syntax

HTTP.Request( options, callback )

Arguments

  • options (table): Configuration for the request.
    • url (string, required): The URL to send the request to.
    • method (string): The HTTP method to use (e.g. "GET", "POST", "PUT", "DELETE"). Defaults to "GET".
    • body (string): The request body. Only applicable for methods that support a body (e.g. POST, PUT).
    • contentType (string): The Content-Type header value. Only used when a body is provided.
    • headers (table): A table of additional headers to include in the request, as key-value string pairs.
    • timeout (number): The maximum time in milliseconds to wait for a response. Defaults to 30000.
  • callback (function): A function to call when the request completes. Receives a response object. See HTTP for the response object structure.

Return Values

No return values.

Examples

HTTP.Request({
    url = "https://example.com/api/data",
    method = "PUT",
    body = String.ToJSON({ status = "active" }),
    contentType = "application/json",
    headers = {
        Authorization = "Bearer my-token",
    },
}, function(response)
    if response.ok then
        print("Update successful.")
    else
        print("Update failed: " .. (response.error or tostring(response.statusCode)))
    end
end)