- Documentation
- Server functions
- callRemote
Function
callRemote
Calls a function exposed by another server over HTTP (arguments go as JSON in a POST request). In the current server version the function does not send the request and returns false; use fetchRemote with toJSON instead.
Syntax
bool callRemote(string url [, any ...])Arguments
urlstring- The address.
...any, optional- Arguments and a
function(result, errno)callback.
Returns
Currently false.
Example
fetchRemote("https://example.com/api/ranking", function(data, errno)
if errno == 0 then outputServerLog(data) end
end, toJSON({ player = "Jan", score = 120 }))
See also
fetchRemoteSends an HTTP or HTTPS request and passes the response to a callback without blocking the server. WithpostDatait makes a POST request, without it a GET. The function gets the response body and a code:0= success, the HTTP status number on a server error,-1when there is no connection or it timed out.toJSONTurns a Lua value (a number, a string, a table, an element) into JSON text, e.g. to store in a file, a database or account data. The format is the same: the result is always a JSON array, and elements are written so thatfromJSONcan read them back. A table that appears a second time (including a table that contains itself) is written as a"^T^n"reference, andfromJSONrestores it as the same table.