Skip to content

API

Provides access to your server-side project api methods. To learn how to create server-side api methods, see the server-side API module.

Screencast Available

Learn how to use the Client API in a screencast format by Clicking here.

Use the core.init method to set the server-side project to call the methods against.

api

core.api.<method-name>([input_params,] listener)

Parameters

Name Description Type Required
input_params Parameters to pass to the api method. Table N
listener The response listener callback function. Function Y

Special Note

If a method does not require a input_params table, you can either pass any empty table, or omit the parameter table all together, supplying just the listener.

Event Response

On success, the result will contain any values that are passed back from the server-side api method.

Example

local function apiListener( evt )
  if evt.error then
    print(evt.error)
  else
    print(evt.result.message) -- Hello
  end
end

-- Assuming you have an "test" server-side method
core.api.test({message="Hello"}, apiListener)

Network Timeout

Though rare, very large workloads may cause the Corona client to throw a network timeout error before you receive a reponse from the server. In these cases you can add a timeout parameter to the input_params table.

The Corona default network timeout is 30 seconds. This is an optional parameter.

Example

local function apiListener( evt )
  ...
end

core.api.test({message="Hello", timeout=60}, apiListener)