FiveM Lua HTTP Wrapper
Latest Release
FiveM Lua HTTP Wrapper
Create endpoints in your resources with ease!
About The Project
This is a library for creating RESTful web endpoints in FiveM server.
Features
Familiar API to those that have worked with express.js
Automatic conversion of tables to data in responses
Object-Oriented approach makes things easier and self-documenting
Middleware functions can be used! (see example)
Supports only GET
and POST
for the time being
Getting Started
Simply download the Latest Release , place into your resources directory and start!
Prerequisites
Just a basic understanding of Lua and HTTP
Configuration
None Required outside of starting in the server.cfg
... (other resources)
ensure fivem-webbed
Usage
The resource alone does nothing. It is a library to be included with another resource to create http endpoints/server files:
--- fxmanifest.lua
server_scripts {
'@fivem-webbed/server/server.lua',
'server/server.lua'
}
--- assume resource is named (api). Looks nice for the URL
--- server/server.lua
local player = Router.new()
player:Get("/:playerId", function(req, res)
local target = tonumber(req:Param("playerId"))
print('Player name', GetPlayerName(target))
return 200, {
name = GetPlayerName(target),
target = target
}
end)
Server.use("/players", player)
Server.listen()
curl -X GET http://localhost:30120/api/players/1
{
"name": "Cyntaax",
"target": 1
}
14 Likes
Great release! Less of a load for my website to handle
Lxk3y
June 23, 2020, 10:50am
6
Fantastic resource, really easy to use. Super super useful
Cyntaax
December 31, 2020, 8:58pm
7
Completely overhauled this. Think its going in a much better direction now.
Well, is there any method to send multiple parameters in a request?
It actually detects the parameters but setting it to nil value.
1 Like
Yeah I’ve got a newer version now with fixes to the parameters and much more, included with my fivem-lua
library. I’ve been debating re-releasing this as a standalone.
Csucsi
July 3, 2021, 2:00pm
10
Then I’m going to check your GitHub to see your lib. Thanks
Cipee
August 9, 2021, 6:11pm
12
hi i’m trying to use your script but i can’t figure out how to put it in resource folder
MINO1
December 26, 2021, 9:34am
13
server.lua (8.9 KB)
This server.lua
file I fixed the Latest Release to get multiple parameters will get nil error (two or more parameters will get nil
value)
Menor4
January 22, 2023, 8:07pm
14
How can I make it so that only one ip can make a request
Hey i can’t see to get it working, tried to using the examples but Not Found: GET /users/steam:9494000210
Hey, this lib has actually been deprecated in favor of this one: GitHub - Cyntaax/fivem-webbed - should fix any issues you’re having
edit: updated the info to point at the new lib! enjoy!
Hey thx for that, can you help in any way with that script or are you not in it any more?
The question: How can i get a header (authorization) from a request, saw the script has this function Request:Header
but no idea how to use it, thx
Check out the example here: fivem-webbed/server.lua at 87aaa638f6eebe09eedb819c919e3b68ffdb5ad6 · Cyntaax/fivem-webbed · GitHub
Seems like you would just need to do
local auth = req:Header("Authorization")
...
Did not see that, i found out you can use req._Raw.headers.authorization
but i think thats better, thx a lot