Skip to main content
Developer library

FiveM RPC

A lightweight request-and-response library for clean communication between FiveM browser, client and server environments.

Communication

Request and response

Cross-environment calls

Call registered server-side handlers directly from your browser or client code.

Returned responses

Await the result in the original environment instead of coordinating separate request and response events.

Authentication example

Configuration

Browser request

Call the registered server handler from your NUI and process the returned character data.

FRONTEND, Calling the server
import rpc from "browser.ts"

rpc.callGlobalServer("auth:sendLoginRequest", {
username: "freamee",
password: "password"
}).then(res => {
console.log(JSON.stringify(res));
// {
// charId = 1
// charName = "Ray Shelby",
// },
// {
// charId = 2,
// charName = "Ray Washington"
// }
});
Configuration

Server handler

Register the matching global RPC handler, perform authentication and return the response.

Serverside, register the event and do the auth, then return a response
exports["fivem-rpc"]:registerGlobal("auth:sendLoginRequest", function(d)
local username = d.username
local password = d.password

-- Perform your authentication checks here.

-- Return the characters available to the authenticated player.
return {
{
charId = 1,
charName = "Ray Shelby",
},
{
charId = 2,
charName = "Ray Washington"
}
}
end)