Can someone explain to me how to use HTTPService? I raelly don’t understand it.
HTTP Service is used to access external information on websites other than roblox, for example, if you wanted to make a feedback system for your game, you could use HTTPService to connect a web hook to send a discord message with the feedback. Or if you wanted to access the current weather to make a realistic weather system, you would find a Weather API, and change the weather in the game accordingly. Watch some tutorials on it, shouldn’t be that hard to understand.
Yes but he wanted an explanation from a developer of the community, not to be provided a documentation link - he most probably has read the documentation and that is why he is coming to the devforum for help
I’m not going to start an argument with you, but you really don’t understand what I’m trying to say
Any more posts you make on this topic saying I’m wrong I’ll just flag since I’m not going to start a petty argument with someone who doesn’t read past replies and instead critisises them for it
there isnt a direct explanation on how to use httpService
you gotta read the documnetation homie to get a grasp of it, or look tutorials on yt or sumn
HTTP service is basically just making web requests between the Roblox game server and external websites, like @JAcoboiskaka1121 said.
First of all, the name. HTTP stands for Hypertext Transfer Protocol, which is a protocol in networking used to transfer plaintext and HTML (Hypertext Markup Language) webpages between computers.
Understanding the 4 main HTTP Request Methods (I’ve skipped PUT
)
GET
This is used only to retrieve information from a web resource; it doesn’t update the resource as it goes. It’s generally pretty safe compared to the other methods. It’s idempotent, meaning all identical requests will have the same result if they succeed.
POST
This submits data to the server in order to create or update a resource. You send data in the request body and it’s processed by the server. It’s not idempotent, different succeeding identical requests will have different results.
PATCH
This is used to partially update an already existing resource. It only changes the specified fields within the resource and nothing else. It’s inconsistently idempotent, identical requests can have the same result but not always.
DELETE
This is used to delete a resource from the server. Not idempotent.
Request structure
Data for a request will typically have 3-4 fields in it. (going off of HttpService
’s RequestAsync
for reference). These fields are:
- Url - the URL of the requested website
- Method - the HTTP method the request should use
- Headers - Data about the request, describes what’s in the
Body
and also can contain authentication material - Body - Data for the request itself
Data formats in the Body
There are many different forms a HTTP body can take, but the most common one is JSON, or JavaScript Object Notation. All of these forms are standards so the websites can communicate information. Websites typically use JavaScript to handle their logic, which is likely why JSON is so common.
Setting up a simple HTTP request
Let’s take an example of unbanning a user in a Roblox game. HTTP service can’t access Roblox API, but for the sake of this example, let’s imagine it can.
local httpService = game:GetService("HttpService")
local apiKey = "" --API key for authentication!
--let's create the request data
local data = {
["Url"] = "https://apis.roblox.com/cloud/v2/universes/UNIVERSE_ID/user-restrictions/USER_ID",
["Method"] = "DELETE", --we want to delete the ban entry
["Headers"] = {
["x-api-key"] = apiKey --include our authentication as request metadata
}
}
--we send the request via RequestAsync
local success, result = pcall(httpService.RequestAsync, httpService, data)
When sending POST, PATCH or PUT requests, you must include the Content-Type
header. It should always be application/
or text/
, and then your data type (respective of whether it’s application or text), for example this for JSON:
{
["Content-Type"] = "application/json"
}
I know this post was pretty long, but I hope it helps! Lmk if u have any questions.
Yeah like @TeamDreams123 said I did read the docs but I really don’t get it so that’s why I made the topic, I didn’t think tutorials were a good idea because you know how tutorials are on youtube…
I’ll read these explanations though from these people and see what I’ll know.
I don’t understand httpservice on the docs at all though, which is weird because other services I’m fine with using the docs except this one.
The only 2 you will probably ever need are GET and POST
All GET does is return the data behind the URL. E.g using GetAsync on an image will return the data it is made of.
All POST does is allow you to send data with the request. This is useful for authentication
So GET is the main one right? What is requestAsync for then?
RequestAsync
is basically the more versatile and flexible way to control your HTTP requests. It also allows for methods like PATCH
and DELETE
which you couldn’t do otherwise.
so, this:
HttpService:PostAsync("ExampleURL", HttpService:JSONEncode(exampleData), Enum.HttpContentType.ApplicationJson, false)
is the same as:
HttpService:RequestAsync({
["Url"] = "ExampleURL",
["Method"] = "POST",
["Headers"] = {
["Content-Type"] = "application/json"
},
["Body"] = HttpService:JSONEncode({exampleData})
})
But, a PATCH request would not be possible without it:
HttpService:RequestAsync({
["Url"] = "ExampleURL",
["Method"] = "PATCH",
["Headers"] = {
["Content-Type"] = "application/json"
},
["Body"] = HttpService:JSONEncode(exampleData)
})
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.