diff --git a/definitions/HTTPRequestDefinition.lua b/definitions/HTTPRequestDefinition.lua new file mode 100644 index 0000000..2d9f9ab --- /dev/null +++ b/definitions/HTTPRequestDefinition.lua @@ -0,0 +1,34 @@ +--- Used by `HTTPApiTable.fetch` and `HTTPApiTable.fetch_async`. +---@class HTTPRequest +local HTTPRequest = { + ---@type string + url = "http://example.org", + + ---@type number @Timeout for request to be completed in seconds. Default depends on engine settings. + timeout = 10, + + ---@type string @`"GET"`, `"POST"`, `"PUT"` or `"DELETE"`. The http method to use. Defaults to "GET". + method = "GET", + + --- Data for the POST, PUT or DELETE request. + --- Accepts both a string and a table. If a table is specified, encodes + --- table as x-www-form-urlencoded key-value pairs. + ---@type string|table @`"Raw request data string"` or `{field1 = "data1", field2 = "data2"}` + data = "example raw request", + + ---@type string? @Optional, if specified replaces the default minetest user agent with given string + user_agent = "ExampleUserAgent", + + ---@type table? @Optional, if specified adds additional headers to the HTTP request. You must make sure that the + --- header strings follow HTTP specification (`"Key: Value"`). + extra_headers = { "Accept-Language: en-us", "Accept-Charset: utf-8" }, + + ---@type boolean? @Optional, if true performs a multipart HTTP request. + --- Default is false. + --- Post only, data must be array + multipart = false, + + --- Deprecated, use `data` instead. Forces `method = "POST"`. + ---@type (string|table)? @`"Raw POST request data string"` or `{field1 = "data1", field2 = "data2"}` + post_data = "Raw POST request data string", +} diff --git a/definitions/HTTPRequestResultDefinition.lua b/definitions/HTTPRequestResultDefinition.lua new file mode 100644 index 0000000..d0b2b43 --- /dev/null +++ b/definitions/HTTPRequestResultDefinition.lua @@ -0,0 +1,18 @@ +--- Passed to `HTTPApiTable.fetch` callback. Returned by `HTTPApiTable.fetch_async_get`. +---@class HTTPRequestResult +local HTTPRequestResult = { + ---@type boolean @If true, the request has finished (either succeeded, failed or timed out) + completed = true, + + ---@type boolean @If true, the request was successful + succeeded = true, + + ---@type boolean @If true, the request timed out + timeout = false, + + ---@type number @HTTP status code + code = 200, + + ---@type string + data = "response", +}