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
:paramsegments, 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) andGET /(route discovery).
Requirements
| Needs | Notes |
|---|---|
tm_lib | The Twilight Moon library: logging and the update check. |
ox_lib | Installed next to tm_lib, which depends on it. |
Install
- Put
tm_apiin your resources folder and start it aftertm_lib, before any resource that registers routes:
cfg
ensure ox_lib
ensure tm_lib
ensure tm_api- 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.
| Convar | Default | Description |
|---|---|---|
api_key | empty | The Bearer token callers must send. Empty rejects every request. |
Pages
| Page | What it covers |
|---|---|
| Exports | registerRoute, registerRouteRaw and unregisterRoute, handler arguments and path rules. |
| Calling the API | The 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
| Version | Notes |
|---|---|
| 1.1.1 | The console prefix uses the Twilight Moon colors. |
| 1.1.0 | Runs on tm_lib: logging through tm.log, the update check, the Twilight Moon manifest and docs. Routes and exports are unchanged. |
| 1.0.0 | First release. |