gw2.api#

local api = require 'gw2.api'

Settings#

The settings for gw2.api are stored in settings/gw2.api.lua.json.

enableCache#
Type:
boolean
Default:
true

Cache results based on request URLs.

Version History

Version

Notes

0.0.1

Added

apiKey#
Type:
string
Default:
null

The api key to use when making requests.

Version History

Version

Notes

0.0.1

Added

Functions#

gw2.api.get(endpoint, params[, done[, err]])#

Perform a request to the given endpoint.

Important

All requests are performed asynchronously on a separate thread, but if done and err are not supplied this function will wait on the for the response using Lua coroutines and return it when it is available.

This means that any function that calls this function in that manner will become a yielding coroutine.

Parameters:
  • endpoint (string) – The GW2 API endpoint to request.

  • params (table) – The query parameters to append to the URL.

  • done (function) – (Optional) A function to call once the request is successfully completed.

  • err (function) – (Optional) A function to call if an error occurs while completing the request.

Returns:

If done and err are nil this function returns either a parsed JSON object or an error string. Otherwise nil.

Example#
local params = {
    ids = "1840,910,2258"
}

-- a synchronous request
local achievements = api.get('achievements', params)

local function done(achievements)
    -- process JSON data
end

local function err(msg)
    -- respond to error
end

-- an asynchronous request
api.get('achievements', params, done, err)

Version History

Version

Notes

0.0.1

Added