From b7c7c17e60ff8720d08be09748b2c8c1b4831440 Mon Sep 17 00:00:00 2001 From: WilsontheWolf <33164598+WilsontheWolf@users.noreply.github.com> Date: Thu, 20 Feb 2025 20:47:24 -0700 Subject: [PATCH 1/2] document SMODS.https --- SMODS.https.md | 33 +++++++++++++++++++++++++++++++++ _Sidebar.md | 1 + 2 files changed, 34 insertions(+) create mode 100644 SMODS.https.md diff --git a/SMODS.https.md b/SMODS.https.md new file mode 100644 index 0000000..250e9c9 --- /dev/null +++ b/SMODS.https.md @@ -0,0 +1,33 @@ +# API Documentation: `SMODS.https` + +The SMODS.https module is a module designed to be compatible with the [lua-https](https://love2d.org/wiki/lua-https) module. The main difference between this and the built in https module is that `SMODS.https` works on more platforms out of the box, compared to Balatro's shipped https modules (which is only availible on Windows by default). + +## Usage + +To use this module you must first `require` it, like so: + +```lua +local https = require "SMODS.https" +``` + +## API Methods + +- `https.request(url, options) -> code, body, headers` + - `url`: The URL to request. + - `options`: Additional optional options for the request. + - `headers`: Additional headers to add to the request as key-value pairs. + - `method` (One of `"GET"|"POST"|"HEAD"|"PUT"|"DELETE"|"PATCH"`): HTTP method. If absent, it's either "GET" or "POST" depending on the data field. + - `data`: Optional additional data to send as application/x-www-form-urlencoded (unless specified otherwise in Content-Type header). + - Return values: + - `code`: HTTP status code, or 0 on failure. + - `body`: The response body on success. Either nil or a description of the error on failure. + - `headers`: HTTP response headers as key-value pairs, or nil on failure. + +## Example Usage + +```lua +local https = require "SMODS.https" + +print(https.request("https://example.com")) +``` + diff --git a/_Sidebar.md b/_Sidebar.md index e9cd211..a8f58ff 100644 --- a/_Sidebar.md +++ b/_Sidebar.md @@ -15,6 +15,7 @@ Game Objects * [SMODS.Voucher](https://github.com/Steamodded/smods/wiki/SMODS.Voucher) * [SMODS.Challenge](https://github.com/Steamodded/smods/wiki/SMODS.Challenge) * [SMODS.DeckSkin](https://github.com/Steamodded/smods/wiki/SMODS.DeckSkin) + * [SMODS.https](https://github.com/Steamodded/smods/wiki/SMODS.https) * [SMODS.Keybind](https://github.com/Steamodded/smods/wiki/SMODS.Keybind) * [SMODS.Language](https://github.com/Steamodded/smods/wiki/SMODS.Language) * [SMODS.ObjectType](https://github.com/Steamodded/smods/wiki/SMODS.ObjectType) From 792ea5644b43289ff10f01d9c409e31820c8235e Mon Sep 17 00:00:00 2001 From: WilsontheWolf Date: Mon, 24 Feb 2025 16:03:58 -0700 Subject: [PATCH 2/2] document https.asyncRequest --- SMODS.https.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/SMODS.https.md b/SMODS.https.md index 250e9c9..ee10179 100644 --- a/SMODS.https.md +++ b/SMODS.https.md @@ -23,11 +23,19 @@ local https = require "SMODS.https" - `body`: The response body on success. Either nil or a description of the error on failure. - `headers`: HTTP response headers as key-value pairs, or nil on failure. +- `https.asyncRequest(url, optionsOrCallback, callback)` + - `url`: The URL to request. + - `optionsOrCallback`: If callback is nil, this can be set to a function instead of the callback. Otherwise is treated like option (see `http.request`) + - `callback`: A function to call when the request is done, or nil if the callback is set in `optionsOrCallback`. + - `callback(code, body, headers)` - The callback to call. For meanings on the values, see `http.request`'s return values + ## Example Usage ```lua local https = require "SMODS.https" -print(https.request("https://example.com")) +print(https.request("https://example.com")) -- Sync request + +https.asyncRequest("https://example.com", print)) -- Async request ```