Harpy → HTTP Methods

HTTP Methods

Callback and Promise variants for GET, POST, PUT, and DELETE — bodies are JSON-encoded automatically and every response has the same consistent shape.

Callback methods

Every method fires in a new thread and calls the callback when the request completes. Omit the callback to fire-and-forget.

harpy:Get(path, callback?)
harpy:Post(path, body?, callback?)
harpy:Put(path, body?, callback?)
harpy:Delete(path, callback?)
-- GET
client:Get("/players/123", function(res)
    if res.ok then
        print(res.data.name, res.data.score)
    else
        warn("fetch failed", res.status)
    end
end)

-- POST | body table is JSON-encoded automatically
client:Post("/events", {
    type   = "round_end",
    winner = "Player1",
    kills  = 12,
})

-- PUT / DELETE
client:Put("/players/123", { score = 9900 })
client:Delete("/sessions/abc")

Promise methods

The *Async variants return a Promise. Resolves with the Response on 2xx; rejects with { message, status, response } on failure.

harpy:GetAsync(path) → Promise
harpy:PostAsync(path, body?) → Promise
harpy:PutAsync(path, body?) → Promise
harpy:DeleteAsync(path) → Promise
client:GetAsync("/leaderboard")
    :Then(function(res)
        return res.data   -- pass data to the next Then
    end)
    :Then(function(data)
        UpdateLeaderboard(data)
    end)
    :Catch(function(err)
        warn("leaderboard fetch failed", err.message, err.status)
    end)

client:PostAsync("/scores", { userId = userId, score = score })
    :Catch(function(err)
        warn("score submit failed", err.status)
    end)

Response shape

Every callback and resolved Promise receives the same object:

FieldTypeDescription
okbooleanTrue if the status code is 2xx.
statusnumberHTTP status code (0 if connection failed).
dataanyJSON-decoded body; raw string if not valid JSON; nil if empty.
headers{ [string]: string }Response headers.
rawstringRaw response body string.

Webhook example

local webhook = Harpy.New({ base = DISCORD_WEBHOOK_URL })

local function NotifyRoundEnd(winner: string, kills: number)
    webhook:Post("", {
        content = string.format("Round over! Winner: **%s** (%d kills)", winner, kills)
    })
end
POST and PUT automatically add Content-Type: application/json when a body table is provided. You do not need to set this header manually.

See also

← Harpy  ·  Configuration | base URL and headers  ·  Retry & Backoff | automatic resilience  ·  Promise | chainable async API