Skip to content

Interface:Routes

Stefan A. Brannfjell edited this page Dec 19, 2017 · 4 revisions

HTTP API routes The routes interface was added in order to allow external web application to query and mutate internal game state via a REST API. By default the REST server is started on port 7174 and is only bound to localhost. It is possible to change these via config.lua, however make sure that if you do you know what you're doing. It is recommended that you run this API behind a reverse proxy (e.g. nginx) to provide TLS and rate limiting.

Available events:

Authenticator:hasPermissions(session, permissions)

Authenticator:onSessionClose()


Authenticator:hasPermissions(session, permissions)

Description: This event runs on every request to check whether a particular API sessions has access to a HTTP resource.
Parameters:

  • session - a table that represents the remote peer's session._
  • _item_ - permissions required to access the resource.
**Accepted return values:** Boolean, false for a 403 Forbidden HTTP response message, otherwise true

Example:

function Authenticator:hasPermissions(session, permissions)
  for _, permission in pairs(permissions) do
  	if (session.permissions[permission] == nil) then
  		return false
  	end
  end

  return true
end 
Authenticator:onSessionClose(session)

Description: This event runs every time a remote peer closes the connection and terminates the session.
Parameters:

  • session - a table that represents the remote peer's session.

Accepted return values: nil

Example:

function Authenticator:onSessionClose(session)
  session.data = nil
end

Added in version: 1.3