-
Notifications
You must be signed in to change notification settings - Fork 4
Use Cases
This page maps common production scenarios to concrete PawnREST APIs.
Scenario
Expose server status and moderation actions to a web dashboard.
Typical flow
- Register routes with
REST_RegisterAPIRoute. - Protect sensitive endpoints with
REST_SetRouteAuthKey. - Read input via
REST_GetParam*,REST_GetQuery*, andGetRequestJsonNode. - Return structured payloads with
RespondNode.
Relevant APIs
REST_RegisterAPIRoute, REST_SetRouteAuthKey, REST_GetRequest*, GetRequestJsonNode, RespondNode
Scenario
Use game server as controlled upload/download hub for maps or patch data.
Typical flow
- Register upload route using
FILE_RegisterRoute. - Set auth and integrity controls (
FILE_AddAuthKey,FILE_SetRequireCRC32). - Enable required REST file operations (
FILE_AllowList,FILE_AllowDownload, etc.). - Observe inbound lifecycle with upload callbacks.
Relevant APIs
FILE_RegisterRoute, FILE_SetConflict, FILE_SetCorruptAction, FILE_Allow*, OnIncomingUploadCompleted
Scenario
Call remote auth/leaderboard/store APIs from gamemode events.
Typical flow
- Create one reusable client per service using
REST_CreateRequestClient. - Dispatch requests with
REST_Request/REST_RequestJSON. - Handle per-request success callbacks and global failure callbacks.
- Inspect structured status/error metadata as needed.
Relevant APIs
REST_CreateRequestClient, REST_Request, REST_RequestJSON, OnRequestFailure, REST_GetRequestErrorCode
Scenario
Subscribe to external real-time event channels (moderation, orchestration, notifications).
Typical flow
- Connect via
REST_WebSocketClientorREST_JsonWebSocketClient. - Process incoming data in callback.
- React to disconnect events and reconnect with your own retry strategy.
Relevant APIs
REST_WebSocketClient, REST_JsonWebSocketClient, REST_JsonWebSocketSend, OnWebSocketDisconnect
Scenario
Push local files from server to an external storage or CI endpoint.
Typical flow
- Queue upload with
FILE_UploadorFILE_UploadWithClient. - Track progress/status (
FILE_GetUploadProgress,FILE_GetUploadStatus). - Handle rich success/failure callbacks.
Relevant APIs
FILE_CreateUploadClient, FILE_UploadWithClient, OnOutgoingUploadCompleted, OnOutgoingUploadFailureDetailed
Scenario
Use PawnREST as a single networking layer inside gamemode.
Typical flow
- Inbound REST for control-plane endpoints.
- Outbound HTTP for service-to-service operations.
- WebSocket for push/event streams.
- JSON node API for one consistent payload model.
Outcome
- fewer external dependencies
- consistent callback and error model
- simpler operational maintenance
For real deployments, pair the above use-cases with:
- route-level auth (
FILE_AddAuthKey,REST_SetRouteAuthKey) - strict upload constraints (extension, size, CRC32)
- TLS-enabled build when using HTTPS/WSS
- explicit handling for structured error callbacks
Scenario
Keep your bot/service layer stateless and let the open.mp server remain the single data authority.
Typical flow
- Expose bot-only routes via
REST_RegisterAPIRouteand protect them usingREST_SetRouteAuthKey. - Read critical identifiers from path/query/header/body as needed (
REST_GetParam*,REST_GetQuery*,REST_GetHeader,GetRequestJsonNode). - Return consistent error payloads (
RespondError) for missing input, not-found, and unauthorized cases. - Keep bot-side logic focused on orchestration/UI while data access stays in gamemode callbacks.
Relevant APIs
REST_RegisterAPIRoute, REST_SetRouteAuthKey, REST_GetParam, REST_GetQuery, REST_GetHeader, GetRequestJsonNode, RespondNode, RespondError
Scenario
Enable Discord bot or admin tools to list, upload, download, and delete files on the server without direct SSH access.
Typical flow
- Register upload route with
FILE_RegisterRoute. - Enable REST file ops:
FILE_AllowList,FILE_AllowDownload,FILE_AllowDelete,FILE_AllowInfo. - Protect with
FILE_AddAuthKey. - Bot/tool calls HTTP endpoints:
-
GET {route}/files— list files (returns{ files: ["a.map", "b.map"] }) -
GET {route}/files/{name}— download file (raw binary) -
GET {route}/files/{name}/info— file metadata -
DELETE {route}/files/{name}— delete file -
POST {route}— upload file (multipart/form-data)
-
Client example (JavaScript/TypeScript):
// List files
const list = await fetch('http://server:8080/maps/files', {
headers: { Authorization: 'Bearer secret-key' }
}).then(r => r.json());
// { success: true, count: 2, files: ["map1.map", "test.json"] }
// Download file
const data = await fetch('http://server:8080/maps/files/map1.map', {
headers: { Authorization: 'Bearer secret-key' }
}).then(r => r.arrayBuffer());
// Upload file
const form = new FormData();
form.append('file', blob, 'newmap.map');
await fetch('http://server:8080/maps', {
method: 'POST',
headers: { Authorization: 'Bearer secret-key' },
body: form
});
// Delete file
await fetch('http://server:8080/maps/files/oldmap.map', {
method: 'DELETE',
headers: { Authorization: 'Bearer secret-key' }
});Relevant APIs
FILE_RegisterRoute, FILE_AddAuthKey, FILE_AllowList, FILE_AllowDownload, FILE_AllowDelete, FILE_AllowInfo