Return Table from website using HTTP Request

Hi! I have been looking into having my script send an HTTPRequest to my website which would then return a table. I know the best scripters/programmers are here on DevForum so I decided to come here after discord attempts. Would you have any ideas or examples on how I could accomplish this?

Thank you! - Chris

I believe you have to deal with JSONEncode and JSONDecode through HttpService, which allows you to transform a JSON table to an ordinary table. Encoding turns it into a really long string(?) and decoding reverses it.

Please refer to About the Scripting Support category. Your current question is phrased up to be asking for code, which is not proper use of this category. There are also no indications that you have attempted this problem or searched for solutions.

When working with HttpService to fetch responses from web servers, you are going to be using a GET request in any medium, whether it’s GetAsync or RequestAsync with the GET method passed to it.

local returnedData = HttpService:GetAsync("yourURL")

Once you have that in, you’re done from Roblox’s side. GetAsync is a callback, so now you need to focus on the web server returning a response to a GET request. I personally don’t know how to do this so that’s up to you to figure out or for someone else to reply with.


@Operatik JSON Encode and Decode are only for responses returned in JSON.

5 Likes

For the roblox side, definitely look at what @colbert2677 has said. If your website is sending json, definitely use JSONDecode which will parse the JSON string (in roblox, json requests might be turn to strings) which will return a Lua table.
i.e.

HttpService:JSONDecode("{'foo':'bar'}") -> {["foo"]="bar"}

As for setting up your own web server, if you need help doing that there’s a ton of great tutorials out there for various languages. Personally I use express.js and return JSON to the get request. The express.js website has a fully in-depth tutorial for returning JSON from requests.

Then you need to find a host, which you could use a variety of different hosts like heroku or even glitch.

1 Like