SetHttpHandler Support, can't get it to work

Hello, I’ve been attempting to figure out SetHTTPHandler and haven’t been able to figure it out. I started by trying to use FiveM-Webbed, then just switched to trying the native. Neither worked, and I just can’t get it to work no matter what I try. I decided to try something simple to try and get it to work, but it still doesn’t. I have the below code in a server.lua, and whenever I attempt to open in in the web it just infinitely loads. I might be missing something really simple, but any help would be appreciated, cheers.

SetHttpHandler(function(req, res)
	local path = req.path


	if req.path == '/test' then
		res.send(json.encode({
			test = 'test'
		}))

		return
	end

end)

this works in just a normal server.lua. I just used the code


image

That’s really odd. Doesn’t work at all on my end.

Could it possibly be because I haven’t port forwarded my network? Or would that not matter?

that shouldn’t matter if your accessing it from a localhost.

I genuinely have no idea what could be the problem then. Really strange.

fxmanifest.lua (87 Bytes)
server.lua (170 Bytes)

both files that im using as basic as can be.

And presumably they simply go in the Resources Folder of FiveM as any other resource?

yep, just create a new folder in the resources folder, drag them in and start then access, http://localhost:30120/resourceName/test

I have no idea then. Thanks for your help anyways, appreciate it.

For some reason re-installing FiveM fixed the issue lol. Thanks again for your help

1 Like

It’s been qute some years! What do you mean when you say re-installing FiveM fixed the issue? Can you elaborate please. Im getting the following reponses:

I am starting the fxserver.exe from my vs code terminal, and using postman to fetch the get api!

Never mind, just got it to work also without having to re - install anything.

Requests needs to be send at ex:
http://localhost:30120//

Means, i have a cayo perico script, i will need to replace the resource-name on the url then call the defined api.