How can I listen for http requests?

For example, I have a website that sends a http request to roblox, using javascript, that sends the message “hello”. How can I have it print “hello”?

2 Likes

If you have the complete system, and are just looking for the print part, use this:

print(tostring(Text)) -- Change "Text" to the variable that decodes the HTTP request, or gets the message from the HTTP request.

This isn’t helpful at all. I specified that I wanted to know how to listen for the http request, not print the text.

1 Like

Ah, yes.

local HttpsService = game:GetService("HttpsService")
local Site = ""

local function retrieveData(Text)
    local Data = {
        ["Content"] = Text
    }

    Data = HttpsService:JSONEncode(Data)
    print(tostring(Data))
end

That might work, not 100% sure, I don’t really use HttpsService. If it doesn’t, I can’t really help you.

This isn’t possible. You would have to have an endpoint on your backend server that is an open GET route for returning data. You would then continuously request that endpoint from Roblox.

That’s really the only way I can think of.

2 Likes

How would I set up that route?

Something like WebSockets should help, however, I’m 99% sure Roblox doesn’t support such protocol.

1 Like

As Dan_PanMan has stated, it is not possible with Roblox’s current HttpService.

Instead, you could periodically send get or post requests to poll for updates.

Just make a GET route on an express server and store a top-level variable named data in the file. When the route is requested, return data and JSONDecode it in Roblox.

in simple terms rather than sending, you set something and wait for roblox to pick it up and tell the server that the code was ran.
so what you need to do is create a page on your server and have it as nothing but the message you want to send then on roblox just continually get that page and get the data and if there is no data then do nothing but if there is then run the code and then send a message to the server to say that the message was read and used then you can clear the text on that page

so in the inspector you would see nothing but your message there or if there is no message then there should be nothing there

An alternative to WebSockets is long polling, you can try this.

1 Like

Another alternative could be using Open Cloud Messaging Service:

I have been using this for my own projects and works fine for sending data, keep in mind it’s still limited and can only manage up to 2kb of data.