Skip to content

tm_api ​

tm_api is the HTTP API gateway for your server. FiveM allows one resource to own the HTTP handler, so this resource owns it and every other resource registers its routes here through exports.

Features ​

  • One handler. One resource owns the port, every other resource registers routes into it.
  • Bearer token auth. Every request needs Authorization: Bearer <token>. The key comes from a convar.
  • Path parameters. Routes support :param segments, for example /players/:id.
  • Auto cleanup. Routes a resource registered are removed when that resource stops.
  • CORS. Open (*) for all origins, and OPTIONS preflight is answered for you.
  • Built in routes. /ping (health check) and GET / (route discovery).

Requirements ​

NeedsNotes
tm_libThe Twilight Moon library: logging and the update check.
ox_libInstalled next to tm_lib, which depends on it.

Install ​

  1. Put tm_api in your resources folder and start it after tm_lib, before any resource that registers routes:
cfg
ensure ox_lib
ensure tm_lib
ensure tm_api
  1. Set the API key in server.cfg:
cfg
set api_key "your-secret-key-here"

If api_key is empty, every request is rejected and a warning is logged.

Settings ​

tm_api has no settings panel. The API key is a secret, so it stays a convar and never goes through the admin panel or the database.

ConvarDefaultDescription
api_keyemptyThe Bearer token callers must send. Empty rejects every request.

Pages ​

PageWhat it covers
ExportsregisterRoute, registerRouteRaw and unregisterRoute, handler arguments and path rules.
Calling the APIThe base URL, authentication, the response format and examples in curl, Node.js and Python.

Languages ​

tm_api has no player or staff text. API responses and console lines are English on purpose, because other programs read them.

Changelog ​

VersionNotes
1.1.0Runs on tm_lib: logging through tm.log, the update check, the Twilight Moon manifest and docs. Routes and exports are unchanged.
1.0.0First release.