Harpy → Configuration

Configuration

Create a Harpy client once per external API, configure its base URL and shared headers, then reuse it across every request.

Constructor

Harpy.New(config?) → Harpy

All config fields are optional. Create as many independent clients as you need — they share no state.

FieldTypeDefaultDescription
basestring""Base URL prepended to every request path.
headers{ [string]: string }{}Headers sent on every request from this client.
retriesnumber3Maximum retry attempts on 5xx or connection error.
local RoExpress = require(game.ReplicatedStorage.RoExpress)
local Harpy     = RoExpress.Harpy

local client = Harpy.New({
    base    = "https://api.example.com",
    retries = 3,   -- optional, default 3
})

Header merging

Headers passed in the config table are merged with any headers set via :SetHeader. Per-request options can add further headers — they are merged in the same way, with per-request headers taking priority over client-level headers.

local client = Harpy.New({
    base    = "https://hooks.slack.com/services/...",
    headers = { ["Content-Type"] = "application/json" },
    retries = 1,
})

-- Add or update headers after construction
client:SetHeader("Authorization", "Bearer " .. SECRET)
client:SetHeader("X-Game-Id", "my-game-123")

Runtime configuration methods

MethodDescription
:SetBase(url)Set or replace the base URL. Applied to all future requests.
:SetHeader(key, value)Add or update a persistent header sent on every request.
:RemoveHeader(key)Remove a persistent header.
:SetRetries(n)Change the maximum retry count. Use 0 to disable retries.

Multiple clients in one game

Each Harpy client is completely independent. Base URL, headers, and retry count are per-instance.

-- Each client has its own base URL and headers
local analyticsClient = Harpy.New({ base = "https://analytics.example.com" })
local webhookClient   = Harpy.New({ base = DISCORD_WEBHOOK_URL, retries = 1 })
local scoresClient    = Harpy.New({ base = "https://scores.example.com" })

analyticsClient:SetHeader("Authorization", "Bearer " .. ANALYTICS_SECRET)
scoresClient:SetHeader("X-Api-Key", SCORES_KEY)
Create one client per external service. Keeping clients separate makes it easy to swap base URLs, rotate keys, and tune retry counts independently.

See also

← Harpy  ·  HTTP Methods | Get, Post, Put, Delete  ·  Retry & Backoff | automatic resilience