HTTP is a lightweight and simple HTTP server for FiveM, inspired by the syntax of Express.js. It aims to provide a familiar and easy-to-use framework for handling HTTP requests and building server-side logic in the FiveM environment.
-
Download the required
ox_lib
dependency from the following link: ox_lib -
Extract the downloaded
ox_lib
archive and place it in theresources
directory of your FiveM server. -
Clone the HTTP repository or download it from the following link: HTTP
-
Extract the downloaded HTTP archive, remove "-fivem-main" from the name, and place it in the
resources
directory of your FiveM server. -
Include
ox_lib
andhttp
in yourserver.cfg
file:ensure ox_lib ensure http
-
Start your FiveM server.
-
Visit
http://localhost:30120/http
in your browser to see the default welcome message.
- Basic routing with a familiar Express.js syntax.
- Middleware support for handling requests.
- Route query string parsing.
- Support for handling GET, POST, and other HTTP methods.
- Parse JSON body.
- Parse cookies.
- Static file serving.
- Cors
- Custom error handling.
- Route params parser.
- Session management.
- WebSocket integration.
- Integration with databases.
- HTML Template support.
- New version warning.
- Refactor route search.
- Request validation and sanitization.
Define routes using Express.js syntax:
local express = require "@http.src.main"
local app = express()
app.get('/', function(req, res)
res.send('Hello, FiveM!')
end)
Use middleware functions to process requests before reaching route handlers:
app.use(function(req, res, next)
print('Request received at', os.date())
next()
end)
Use the listen
function to make it live and listen on your FiveM server:
local listen = app.listen(function()
print("Listening on the FiveM server\nExample: http://localhost:30120/"..GetCurrentResourceName().."/")
end)
SetHttpHandler(listen)
For more examples, visit the file example/main.lua
.
Contributions are welcome! Feel free to open issues or submit pull requests to improve HTTP.
HTTP is licensed under the MIT License - see the LICENSE file for details.
Enjoy using HTTP in your FiveM server! If you have any questions or suggestions, feel free to reach out.