Hey there, this post will teach you how to use endpoints. For a while I didn’t know how JSon worked and always knew it played a big part in programming. I decided to research it but nothing online made sense. To think of it, it plays a major role in this tutorial. My simple definition for it is basically a string to a table converter.
You might be wondering why you should learn this… In the future many jobs would love to hire people who can use JSon and use post and get methods.
To begin, you might be wondering why you would even use it, simple… To fetch data
Suppose you went to a website and wanted to collect data, you might use surveys or different techniques of obtaining data but that takes effort. Endpoints are here to help.
The list of current known endpoints for roblox:
With this I will talk about proxies. Proxies are like vpn’s, although it filters data and responses.
Proxies are essential since roblox doesn’t allow requests to their own site. The proxy will be used to send data to and from the site to your game.
An example proxy would be heroku or rprxy.xyz, I will get into detail with the code soon. Without a proxy you might recieve an error along the lines of Trust check failed
An appropriate endpoint I will be using in this example is devforum.
You can get the endpoint by typing devforum.roblox.com/u/username.json
Let’s get into the code now but before that make sure HTTP requests are on.
local HttpService = game:GetService("HttpService")
local function GetDevforumStats(username)
local data = Proxy:Get("https://devforum.roblox.com/u/"..username..".json")
local ReturnedJSon = HttpService:JSONDecode(data)
return ReturnedJSon
end
In this example, I fetched the data using a proxy since devforums is linked to roblox. The data is currently raw and will be shown as a string. To convert it to a table you would use HttpService:JSONDecode(json string)
Currently I am using the Get method as shown in the example… That will get the data, the get method is not as safe as the post method but is much easier to use.
If you don’t understand how to create a proxy and get it in the format I did above, you could also do this:
local HttpService = game:GetService("HttpService")
local function GetDevforumStats(username)
local data = HttpService:GetAsync("https://devforum.rprxy.xyz/u/"..username..".json")
local ReturnedJSon = HttpService:JSONDecode(data)
return ReturnedJSon
end
Now since you understand that, I will get into the details of how cursors work in endpoints, an example of this would be the badges api. Badges Api
Think of it as a unique key that is used to go to the next page or previous page. Ways to use this:
local function GetBadges2(id)
local b = HttpService:GetAsync("https://badges.rprxy.xyz/v1/users/"..id.."/badges?limit=100&sortOrder=Asc")
b = HttpService:JSONDecode(b)
local totalBadges = 0
while b.nextPageCursor do
totalBadges = totalBadges + #b.data
b = HttpService:GetAsync("https://badges.rprxy.xyz/v1/users/"..id.."/badges?limit=100&cursor="..b.nextPageCursor.."&sortOrder=Asc")
b = HttpService:JSONDecode(b)
print(totalBadges)
end
return totalBadges
end
In this example I am looping the next page cursor to get every badge the user owns. As shown by b.nextPageCursor.."&sortOrder=Asc"
, In the example, I am setting b to the newest cursor then looping it till the last page.
These are the basics, in the future, you would have to cope with headers and using tokens. For now this shall suffice. Thank you for taking the time to read my tutorial.
You can use postman to create endpoints. https://www.postman.com/
Updates:
Edit 1 - 11/17/20 .body is no longer needed, before: HttpService:JSONDecode(data.body)
after: HttpService:JSONDecode(data)
Edit 2 - 9/26/21 rprxy no longer available, rely on your own proxy by using sites such as heroku.