Service · inherits Instance
HttpService
Allows sending HTTP requests and provides various web-related and JSON methods.
About HttpService
HttpService allows HTTP requests to be sent from experience servers using
RequestAsync,
GetAsync and
PostAsync. This service allows experiences to
be integrated with third-party web services such as analytics, data storage,
remote server configuration, error reporting, advanced calculations, or
real-time communication. Additionally, it can call a subset of the Open Cloud
APIs.
For more information about these use cases, see In-experience HTTP requests.
HttpService also houses the JSONEncode and
JSONDecode methods, which are useful for
communicating with services that use the JSON format. In
addition, the GenerateGUID method provides
random 128‑bit labels which can be treated as probabilistically unique in a
variety of scenarios.
Within Studio, use
CreateWebStreamClient() to process
data in real time from servers that support streaming protocols such as
SSE,
chunked transfer encoding,
and WebSockets. You can connect
callback functions to stream events, allowing you to process data immediately
as it arrives instead of waiting for the entire response to complete.
Only send HTTP requests to trusted third-party platforms to avoid introducing unnecessary security risks to your experience.
Properties 1
HttpEnabled
: booleanIndicates whether HTTP requests can be sent to external websites.When set to
true, allows scripts to send requests to websites usingHttpService.GetAsync,HttpService.PostAsync, andHttpService.RequestAsync.This property must be toggled on for unpublished experiences by setting this property to
trueusing the Command Bar:game:GetService("HttpService").HttpEnabled = true
Methods 9
CreateWebStreamClient
(streamClientType: WebStreamClientType, requestOptions: Dictionary) → WebStreamClientCreates a client that opens a persistent connection to stream data.This method creates a client that establishes a long-lived connection to servers utilizing various streaming technologies, such as Server-Sent Events (SSE). After the connection is established, the client fires signals that you can connect callback functions to with
RBXScriptConnection. Use these callbacks to process messages as soon as they arrive, as well as respond to open, close, and error events.There is a limit of four total clients allowed at one time. Close streams that you no longer need with
WebStreamClient.Close. When the stream is no longer needed, you should disconnect any associatedRBXScriptConnectionsto avoid memory leaks.This method is available in Studio only. If you use it inside scripts, make sure to remove any references before publishing the experience. We encourage you to create plugins with this feature for reusability and ease of use.
GenerateGUID
(wrapInCurlyBraces: boolean = true) → stringGenerates a UUID/GUID random string, optionally with curly braces.This method generates a random universally unique identifier (UUID) string. The sixteen octets of a UUID are represented as 32 hexadecimal (base 16) digits, displayed in five groups separated by hyphens in the form
8-4-4-4-12for a total of 36 characters, for example123e4567-e89b-12d3-a456-426655440000.The UUID specification used is Version 4 (random), variant 1 (DCE 1.1, ISO/IEC 11578:1996). UUIDs of this version are the most commonly used due to their simplicity, as they are entirely randomly generated. Note that this version does not have certain features that other UUID versions have, such as encoded timestamps, MAC addresses, or time-based sorting like UUIDv7 or ULID.
There are over 5.3×1036 unique v4 UUIDs, in which the probability of finding a duplicate within 103 trillion UUIDs is one in a billion.
The
wrapInCurlyBracesargument determines whether the returned string is wrapped in curly braces ({}). For instance:true:{94b717b2-d54f-4340-a504-bd809ef5bf5c}false:db454790-7563-44ed-ab4b-397ff5df737b
This method can be used regardless of whether HTTP requests are enabled.
GetAsync
(url: Variant, nocache: boolean = false, headers: Variant) → stringYieldsSends an HTTPGETrequest.This method sends an HTTP
GETrequest. It functions similarly toRequestAsync()except that it accepts HTTP request parameters as method parameters instead of a single dictionary and returns only the body of the HTTP response. Generally, this method is useful only as a shorthand andRequestAsync()should be used in most cases.When
true, thenocacheparameter prevents this method from caching results from previous calls with the sameurl.The
urlparameter also accepts aSecretvalue; useGetSecretcombined withAddPrefixandAddSuffixto safely embed secret credentials (such as API keys) directly in the URL without exposing their values.GetSecret
(key: string) → SecretReturns aSecretfrom the secrets store.This method returns a value previously added to the secrets store for the experience. The secret content is not printable and not available when the experience runs locally.
The returned
Secretcan be transformed using built-in methods such asSecret.AddPrefix. It is expected to be sent as a part of an HTTP request.For more information, see the usage guide.
JSONDecode
(input: string) → VariantDecodes a JSON string into a Luau table.This method transforms a JSON object or array into a Luau table with the following characteristics:
- Keys of the table are strings or numbers but not both. If a JSON object contains both, string keys are ignored.
- An empty JSON object generates an empty Luau table (
{}). - If the
inputstring is not a valid JSON object, this method will throw an error.
To encode a Luau table into a JSON object, use the
HttpService.JSONEncodemethod.This method can be used regardless of whether HTTP requests are enabled.
JSONEncode
(input: Variant) → stringGenerate a JSON string from a Luau table.This method transforms a Luau table into a JSON object or array based on the following guidelines:
- Keys of the table must be either strings or numbers. If a table contains both, an array takes priority (string keys are ignored).
- An empty Luau table (
{}) generates an empty JSON array (e.g.[]). - Whether passing a dictionary table or a numerically indexed table, avoid
nilvalues for any index. - Cyclic table references cause an error.
This method allows values such as
infandnanwhich are not valid JSON. This may cause problems if you want to use the outputted JSON elsewhere.This method also accepts
buffersup to 50 MiB, which it encodes to base64 (and often compresses) before converting to a JSON object.To reverse the encoding process and decode a JSON object, use the
HttpService.JSONDecodemethod.This method can be used regardless of whether HTTP requests are enabled.
PostAsync
(url: Variant, data: string, content_type: HttpContentType = ApplicationJson, compress: boolean = false, headers: Variant) → stringYieldsSends an HTTPPOSTrequest.This method sends an HTTP
POSTrequest. It functions similarly toRequestAsync()except that it accepts HTTP request parameters as method parameters instead of a single dictionary and returns only the body of the HTTP response. Generally, this method is useful only as a shorthand andRequestAsync()should be used in most cases.When
true, thecompressparameter controls whether a large request body is compressed using gzip.The
urlparameter also accepts aSecretvalue — useGetSecretcombined withAddPrefixandAddSuffixto safely embed secret credentials (such as API keys) directly in the URL without exposing their values.RequestAsync
(requestOptions: Dictionary) → DictionaryYieldsSends an HTTP request using any HTTP method given a dictionary of information.This method sends an HTTP request using a dictionary to specify the request data, such as the target URL, method, headers, and request body data. It returns a dictionary that describes the response data received. Optionally, the request can be compressed using
HttpCompression.Request dictionary fields
Supported HTTP methods
The HTTP request methods specify the purpose of the request being made and what is expected if the request is successful. For instance, the
GETrequest method tells the server at the requested address that a resource is being requested and, if it succeeds, the resource at that address will be returned. Similarly, theHEADrequest method does the same except the server knows to return a response without aBodyelement.HTTP headers
In the request dictionary, you can specify custom HTTP headers to use in the request. However, some headers cannot be specified. For example,
Content-Lengthis determined from the request body.User-AgentandRoblox-Idare locked by Roblox. Other headers likeAcceptorCache-Controluse default values but can be overridden. More commonly, some REST APIs may require API keys or other service authentication to be specified in request headers.The
RequestAsync()method does not detect the format of body content. Many web servers require theContent-Typeheader be set appropriately when sending certain formats. Other methods ofHttpServiceuse theHttpContentTypeenum; for this method set theContent-Typeheader appropriately:text/plain,text/xml,application/xml,application/jsonorapplication/x-www-form-urlencodedare replacementContent-Typeheader values for the respective enum values.Response dictionary fields
RequestAsync()returns a dictionary containing the following fields:Error Cases
RequestAsync()raises an error if the response times out or if the target server rejects the request. If a web service goes down for some reason, it can cause scripts that use this method to stop functioning altogether. It is often a good idea to wrap calls to this method inLuaGlobals.pcalland gracefully handle failure cases if the required information isn't available.Limitations
The current limitation for sending and receiving external HTTP requests is 500 requests per minute. There is also a separate limit of 2500 requests per minute for Open Cloud requests. Requests over these thresholds will fail.
UrlEncode
(input: string) → stringReplaces URL-unsafe characters with '%' and two hexadecimal characters.This method percent-encodes a given string so that reserved characters properly encoded with
%and two hexadecimal characters.This is useful when formatting URLs for use with
HttpService.GetAsync/HttpService.PostAsync, orPOSTdata of the media typeapplication/x-www-form-urlencoded(Enum.HttpContentType.ApplicationUrlEncoded).For instance, when you encode the URL
https://www.roblox.com/discover#/, this method returnshttps%3A%2F%2Fwww%2Eroblox%2Ecom%2Fdiscover%23%2F.
HttpService also has every member of Instance. Deprecated and Roblox-only members are hidden.
Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.