Network → Async API

Async / Promise API

The Async variants of every request method return a Promise instead of accepting a callback, letting you chain Then, Catch, and Finally for readable multi-step flows.

Signatures

GET network:GetAsync(route, data?) → Promise
POST network:PostAsync(route, data?) → Promise
PUT network:PutAsync(route, data?) → Promise
DELETE network:DeleteAsync(route, data?) → Promise

Parameters are identical to the callback methods — only the return value changes. See Request Methods for parameter details.

Basic chaining

Use :Then() to transform the resolved value, :Catch() to handle any error in the chain, and :Finally() to run code whether it resolved or rejected.

network:GetAsync("inventory/items")
    :Then(function(res) return res.data.items end)
    :Then(function(items) populateUI(items) end)
    :Catch(function(err) warn(err.message) end)

Post with body

network:PostAsync("player/123/update", { name = "NewName" })
    :Then(function(res)
        print("Saved with status", res.status)
    end)
    :Catch(function(err)
        warn("Update failed:", err.message)
    end)

Sequential requests

Return a Promise from inside :Then() to chain requests in order — the next :Then() waits for it.

network:GetAsync("shop/catalogue")
    :Then(function(res)
        ShopUI:Load(res.data)
        return network:GetAsync("player/data")   -- second request after first resolves
    end)
    :Then(function(res)
        CoinsUI:Set(res.data.coins)
    end)
    :Catch(function(err)
        UI:ShowError("Load failed:", err.message)
    end)

Finally

:Finally(fn) runs whether the Promise resolved or rejected — useful for hiding a loading spinner regardless of outcome.

LoadingSpinner.Visible = true

network:GetAsync("leaderboard")
    :Then(function(res) LeaderboardUI:Populate(res.data) end)
    :Catch(function(err) warn(err.message) end)
    :Finally(function()
        LoadingSpinner.Visible = false  -- always hides
    end)
Promise shape. The resolved value passed to :Then() is the full NetworkResponse table — access res.data, res.status etc. The rejection value passed to :Catch() is also a NetworkResponse with type == "error" or "timeout". See Promise Creation for details.

Relationship to the Promise module

The objects returned by the Async methods implement :Then(), :Catch(), and :Finally(). See Promise for the full API reference and chaining patterns.

See also

← Network  ·  Request Methods | callback-based variants  ·  Promise | Then, Catch, Finally reference  ·  Promise Chaining | error propagation patterns  ·  Cancel & Timeout | abort in-flight requests