HttpService
Allows sending HTTP requests and provides various web-related and JSON methods.
Memory category | Instances |
---|
Member index 13
Description
HttpService
allows HTTP requests to be sent from game servers using
RequestAsync,
GetAsync and
PostAsync. This service allows games to be
integrated with off-Roblox web services such as analytics, data storage,
remote server configuration, error reporting, advanced calculations or
real-time communication.
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.
You should only send HTTP requests to trusted third-party platforms to avoid making your experience vulnerable to security risks.
This property cannot be interacted with at runtime.
Enable HTTP requests
Request-sending methods aren't enabled by default. To send requests, you must enable HTTP requests for your experience.
Use in plugins
HttpService
can be used by Studio plugins. They may do this to check for
updates, send usage data, download content, or other business logic. The first
time a plugin attempts to do this, the user may be prompted to give the plugin
permission to communicate with the particular web address. A user may accept,
deny, and revoke such permissions at any time through the Plugin
Management window.
Plugins may also communicate with other software running on the same computer
through the localhost
and 127.0.0.1
hosts. By running programs compatible
with such plugins, you can extend the functionality of your plugin beyond the
normal capabilities of Studio, such as interacting with your computer's file
system. Beware that such software must be distributed separately from the
plugin itself and can pose security hazards if you aren't careful.
Additional considerations
- There are port restrictions. You cannot use port
1194
or any port below1024
, except80
and443
. If you try to use a blocked port, you will receive either a403 Forbidden
orERR_ACCESS_DENIED
error. - For each Roblox game server, there is a limit of 500 HTTP requests per minute. Exceeding this may cause request-sending methods to stall entirely for about 30 seconds.
- Requests cannot be made to any Roblox website, such as www.roblox.com.
- Web requests can fail for many reasons, so it is important to "code defensively" (use pcall()) and have a plan for when requests fail.
- Although the
http://
protocol is supported, you should usehttps://
wherever possible. - Requests sent should provide a secure form of authentication, such as a pre-shared secret key, so that bad actors cannot pose as one of your Roblox game servers.
- Be aware of the general capacity and rate-limiting policies of the web servers to which requests are being sent.
History 55
- 622 Change Parameters of PostAsync from (url: string, data: string, content_type: HttpContentType = ApplicationJson, compress: bool = false, headers: Variant) to (url: Variant, data: string, content_type: HttpContentType = ApplicationJson, compress: bool = false, headers: Variant)
- 622 Change Parameters of GetAsync from (url: string, nocache: bool = false, headers: Variant) to (url: Variant, nocache: bool = false, headers: Variant)
- 615 Change ReadSecurity of HttpEnabled from LocalUserSecurity to None
- 596 Add GetSecret
- 573 Change ReturnType of SetHttpEnabled from void to null
- 557 Change Tags of JSONDecode from [] to [CustomLuaState]
- 554 Change Tags of JSONDecode from [CustomLuaState] to []
- 555 Change Tags of JSONDecode from [] to [CustomLuaState]
- 554 Change Tags of JSONEncode from [] to [CustomLuaState]
- 553 Change Default of HttpEnabled from to false
- 538 Change ThreadSafety of UrlEncode from Unsafe to Safe
- 538 Change ThreadSafety of JSONEncode from Unsafe to Safe
- 538 Change ThreadSafety of JSONDecode from Unsafe to Safe
- 538 Change ThreadSafety of GenerateGUID from Unsafe to Safe
- 486 Change ThreadSafety of HttpEnabled from ReadOnly to ReadSafe
- 462 Change ThreadSafety of UrlEncode from to Unsafe
- 462 Change ThreadSafety of SetHttpEnabled from to Unsafe
- 462 Change ThreadSafety of RequestInternal from to Unsafe
- 462 Change ThreadSafety of RequestAsync from to Unsafe
- 462 Change ThreadSafety of PostAsync from to Unsafe
- 462 Change ThreadSafety of JSONEncode from to Unsafe
- 462 Change ThreadSafety of JSONDecode from to Unsafe
- 462 Change ThreadSafety of GetUserAgent from to Unsafe
- 462 Change ThreadSafety of GetHttpEnabled from to Unsafe
- 462 Change ThreadSafety of GetAsync from to Unsafe
- 462 Change ThreadSafety of GenerateGUID from to Unsafe
- 462 Change ThreadSafety of HttpEnabled from to ReadOnly
- 412 Add GetUserAgent
- 352 Add RequestInternal
- 351 Add SetHttpEnabled
- 351 Add GetHttpEnabled
- 350 Remove SetHttpEnabled
- 350 Remove GetHttpEnabled
- 351 Add SetHttpEnabled
- 351 Add GetHttpEnabled
- 343 Add RequestAsync
- 251 Change Parameters of PostAsync from (url: string, data: string, content_type: HttpContentType = ApplicationJson, compress: bool = false) to (url: string, data: string, content_type: HttpContentType = ApplicationJson, compress: bool = false, headers: Variant)
- 251 Change Parameters of GetAsync from (url: string, nocache: bool = false) to (url: string, nocache: bool = false, headers: Variant)
- 250 Change Parameters of PostAsync from (url: string, data: string, content_type: HttpContentType = ApplicationJson, compress: bool = false, headers: Variant) to (url: string, data: string, content_type: HttpContentType = ApplicationJson, compress: bool = false)
- 250 Change Parameters of GetAsync from (url: string, nocache: bool = false, headers: Variant) to (url: string, nocache: bool = false)
- 251 Change Parameters of PostAsync from (url: string, data: string, content_type: HttpContentType = ApplicationJson, compress: bool = false) to (url: string, data: string, content_type: HttpContentType = ApplicationJson, compress: bool = false, headers: Variant)
- 251 Change Parameters of GetAsync from (url: string, nocache: bool = false) to (url: string, nocache: bool = false, headers: Variant)
- 220 Change Parameters of PostAsync from (url: string, data: string, content_type: HttpContentType = ApplicationJson) to (url: string, data: string, content_type: HttpContentType = ApplicationJson, compress: bool = false)
- 170 Change Parameters of GenerateGUID from () to (wrapInCurlyBraces: bool = true)
- 138 Add GenerateGUID
- 130 Change Parameters of JSONEncode from (input: Dictionary) to (input: Variant)
- 130 Change ReturnType of JSONDecode from Dictionary to Variant
- 128 Add UrlEncode
- 128 Change Parameters of GetAsync from (url: string) to (url: string, nocache: bool = false)
- 122 Add PostAsync
- 122 Add JSONEncode
- 122 Add JSONDecode
- 122 Add GetAsync
- 122 Add HttpEnabled
- 122 Add HttpService
Members 13
GenerateGUID
Parameters (1) | Default | |
---|---|---|
wrapInCurlyBraces | bool | true |
Returns (1) | ||
string |
This method randomly creates a [universally unique identifier
UUID
string. The sixteen octets of a UUID are represented as 32 hexadecimal
(base 16) digits, displayed in 5 groups separated by hyphens in the form
8-4-4-4-12
for a total of 36 characters, for example
123e4567-e89b-12d3-a456-426655440000
.
The wrapInCurlyBraces
argument determines whether the returned string is
wrapped in curly braces ({}
). For instance:
true
:{94b717b2-d54f-4340-a504-bd809ef5bf5c}
false
:db454790-7563-44ed-ab4b-397ff5df737b
Thread safety | Safe |
---|
History 4
- 538 Change ThreadSafety of GenerateGUID from Unsafe to Safe
- 462 Change ThreadSafety of GenerateGUID from to Unsafe
- 170 Change Parameters of GenerateGUID from () to (wrapInCurlyBraces: bool = true)
- 138 Add GenerateGUID
GetAsync
Parameters (3) | Default | |
---|---|---|
url | Variant | |
nocache | bool | false |
headers | Variant | |
Returns (1) | ||
string |
This method sends an HTTP GET
request. It functions similarly to
RequestAsync() 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 and
RequestAsync() should to be used in
most cases.
When true
, the nocache
parameter prevents this method from caching
results from previous calls with the same url
.
Thread safety | Unsafe |
---|
History 7
- 622 Change Parameters of GetAsync from (url: string, nocache: bool = false, headers: Variant) to (url: Variant, nocache: bool = false, headers: Variant)
- 462 Change ThreadSafety of GetAsync from to Unsafe
- 251 Change Parameters of GetAsync from (url: string, nocache: bool = false) to (url: string, nocache: bool = false, headers: Variant)
- 250 Change Parameters of GetAsync from (url: string, nocache: bool = false, headers: Variant) to (url: string, nocache: bool = false)
- 251 Change Parameters of GetAsync from (url: string, nocache: bool = false) to (url: string, nocache: bool = false, headers: Variant)
- 128 Change Parameters of GetAsync from (url: string) to (url: string, nocache: bool = false)
- 122 Add GetAsync
GetHttpEnabled
Parameters (0) | ||
---|---|---|
No parameters. | ||
Returns (1) | ||
bool |
Security | RobloxScriptSecurity |
---|---|
Thread safety | Unsafe |
History 4
- 462 Change ThreadSafety of GetHttpEnabled from to Unsafe
- 351 Add GetHttpEnabled
- 350 Remove GetHttpEnabled
- 351 Add GetHttpEnabled
GetSecret
Parameters (1) | ||
---|---|---|
key | string | |
Returns (1) | ||
Secret |
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 Secret can be transformed using built-in methods such as Secret:AddPrefix(). It is expected to be sent as a part of an HTTP request.
For more information, see the usage guide.
Thread safety | Safe |
---|
GetUserAgent
Parameters (0) | ||
---|---|---|
No parameters. | ||
Returns (1) | ||
string |
Security | RobloxScriptSecurity |
---|---|
Thread safety | Unsafe |
History 2
- 462 Change ThreadSafety of GetUserAgent from to Unsafe
- 412 Add GetUserAgent
HttpEnabled
Type | Default | |
---|---|---|
bool | false |
When set to true
, allows scripts to send requests to websites using
HttpService:GetAsync(), HttpService:PostAsync(), and
HttpService:RequestAsync().
This property must be toggled on through the
Game Settings interface in Studio, or
for unpublished experiences by setting this property to true
using
the Command Bar:
game:GetService("HttpService").HttpEnabled = true
Write security | LocalUserSecurity |
---|---|
Thread safety | ReadSafe |
Category | Data |
Loaded/Saved | true |
History 5
- 615 Change ReadSecurity of HttpEnabled from LocalUserSecurity to None
- 553 Change Default of HttpEnabled from to false
- 486 Change ThreadSafety of HttpEnabled from ReadOnly to ReadSafe
- 462 Change ThreadSafety of HttpEnabled from to ReadOnly
- 122 Add HttpEnabled
JSONDecode
Parameters (1) | ||
---|---|---|
input | string | |
Returns (1) | ||
Variant |
This method transforms a JSON object or array into a Lua 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 Lua table (
{}
). - If the
input
string is not a valid JSON object, this method will throw an error.
To encode a Lua table into a JSON object, use the HttpService:JSONEncode() method.
This method can be used regardless of whether HTTP requests are enabled.
Thread safety | Safe |
---|
History 7
- 557 Change Tags of JSONDecode from [] to [CustomLuaState]
- 554 Change Tags of JSONDecode from [CustomLuaState] to []
- 555 Change Tags of JSONDecode from [] to [CustomLuaState]
- 538 Change ThreadSafety of JSONDecode from Unsafe to Safe
- 462 Change ThreadSafety of JSONDecode from to Unsafe
- 130 Change ReturnType of JSONDecode from Dictionary to Variant
- 122 Add JSONDecode
JSONEncode
Parameters (1) | ||
---|---|---|
input | Variant | |
Returns (1) | ||
string |
This method transforms a Lua 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 Lua table (
{}
) generates an empty JSON array.The value
nil
is never generated.Cyclic table references cause an error.
This method allows values such as
inf
andnan
which are not valid JSON. This may cause problems if you want to use the outputted JSON elsewhere.
To reverse the encoding process and decode a JSON object, use the HttpService:JSONDecode() method.
This method can be used regardless of whether HTTP requests are enabled.
Thread safety | Safe |
---|
History 5
- 554 Change Tags of JSONEncode from [] to [CustomLuaState]
- 538 Change ThreadSafety of JSONEncode from Unsafe to Safe
- 462 Change ThreadSafety of JSONEncode from to Unsafe
- 130 Change Parameters of JSONEncode from (input: Dictionary) to (input: Variant)
- 122 Add JSONEncode
PostAsync
Parameters (5) | Default | |
---|---|---|
url | Variant | |
data | string | |
content_type | HttpContentType | ApplicationJson |
compress | bool | false |
headers | Variant | |
Returns (1) | ||
string |
This method sends an HTTP POST
request. It functions similarly to
RequestAsync() 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 and
RequestAsync() should to be used in
most cases.
When true
, the compress
parameter controls whether large request
bodies will be compressed using gzip.
Thread safety | Unsafe |
---|
History 7
- 622 Change Parameters of PostAsync from (url: string, data: string, content_type: HttpContentType = ApplicationJson, compress: bool = false, headers: Variant) to (url: Variant, data: string, content_type: HttpContentType = ApplicationJson, compress: bool = false, headers: Variant)
- 462 Change ThreadSafety of PostAsync from to Unsafe
- 251 Change Parameters of PostAsync from (url: string, data: string, content_type: HttpContentType = ApplicationJson, compress: bool = false) to (url: string, data: string, content_type: HttpContentType = ApplicationJson, compress: bool = false, headers: Variant)
- 250 Change Parameters of PostAsync from (url: string, data: string, content_type: HttpContentType = ApplicationJson, compress: bool = false, headers: Variant) to (url: string, data: string, content_type: HttpContentType = ApplicationJson, compress: bool = false)
- 251 Change Parameters of PostAsync from (url: string, data: string, content_type: HttpContentType = ApplicationJson, compress: bool = false) to (url: string, data: string, content_type: HttpContentType = ApplicationJson, compress: bool = false, headers: Variant)
- 220 Change Parameters of PostAsync from (url: string, data: string, content_type: HttpContentType = ApplicationJson) to (url: string, data: string, content_type: HttpContentType = ApplicationJson, compress: bool = false)
- 122 Add PostAsync
RequestAsync
Parameters (1) | ||
---|---|---|
requestOptions | Dictionary | |
Returns (1) | ||
Dictionary |
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
Name | Type | Required | Description |
---|---|---|---|
Url | String | yes | The target URL for this request. Must use http or https protocols. |
Method | String | no | The HTTP method being used by this request, most often GET or POST . |
Headers | Dictionary | no | A dictionary of headers to be used with this request. Most HTTP headers are accepted here, but not all. |
Body | String | no | The request body. Can be any string, including binary data. Must be excluded when using the GET or HEAD HTTP methods. It might be necessary to specify the Content-Type header when sending JSON or other formats. |
Compress | HttpCompression | no | An optional compression field that will compress the data in the request. The value can either be HttpCompression.None or HttpCompression.Gzip. |
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 GET
request 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, the HEAD
request method does the same except the
server knows to return a response without a Body
element.
Method | Description | Safe |
---|---|---|
GET ⓘ | The GET method requests the resource at the specified address. Does not support use of the Body parameter. | Yes |
HEAD ⓘ | The HEAD method requests a response identical to a GET request, but with no response body. Does not support use of the Body parameter. | Yes |
POST ⓘ | The POST method submits the supplied Body data to the requested address. | No |
PUT ⓘ | The PUT method replaces all current iterations of the resource specified within the supplied Body data. | No |
DELETE ⓘ | The DELETE method deletes the resource specified in the supplied Body data at the requested address. | No |
OPTIONS ⓘ | The OPTIONS method requests the permitted communication options for the supplied address. | Yes |
TRACE ⓘ | The TRACE method performs a message loop-back test along the path to the resource specified in the supplied Body data. | Yes |
PATCH ⓘ | The PATCH method applies partial changes to the resource specified in the supplied Body data at the requested address. | No |
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-Length
is determined from the request body. User-Agent
and
Roblox-Id
are locked by Roblox. Other headers like Accept
or
Cache-Control
use 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 the Content-Type
header be set appropriately
when sending certain formats. Other methods of HttpService use the
HttpContentType enum; for this method set the Content-Type
header
appropriately: text/plain
, text/xml
, application/xml
,
application/json
or application/x-www-form-urlencoded
are replacement
Content-Type
header values for the respective enum values.
Response dictionary fields
RequestAsync()
returns a dictionary containing the following fields:
Name | Type | Description |
---|---|---|
Success | Boolean | The success status of the request. This is true if and only if the StatusCode lies within the range 200 -299 . |
StatusCode | Integer | The HTTP response code identifying the status of the response. |
StatusMessage | String | The status message that was sent back. |
Headers | Dictionary | A dictionary of headers that were set in this response. |
Body | The request body (content) received in the response. |
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 in
pcall() and gracefully handle failure cases if the
required information isn't available.
Limitations
The current limitation for sending and receiving HTTP requests is 500 requests per minute. Requests over this threshold will fail. Additionally, Roblox domains are excluded. This means that HTTP requests cannot be sent to any Roblox-owned site such as www.roblox.com.
Thread safety | Unsafe |
---|
History 2
- 462 Change ThreadSafety of RequestAsync from to Unsafe
- 343 Add RequestAsync
RequestInternal
Parameters (1) | ||
---|---|---|
options | Dictionary | |
Returns (1) | ||
Instance |
Security | RobloxScriptSecurity |
---|---|
Thread safety | Unsafe |
History 2
- 462 Change ThreadSafety of RequestInternal from to Unsafe
- 352 Add RequestInternal
SetHttpEnabled
Parameters (1) | ||
---|---|---|
enabled | bool | |
Returns (1) | ||
null |
Security | RobloxScriptSecurity |
---|---|
Thread safety | Unsafe |
History 5
- 573 Change ReturnType of SetHttpEnabled from void to null
- 462 Change ThreadSafety of SetHttpEnabled from to Unsafe
- 351 Add SetHttpEnabled
- 350 Remove SetHttpEnabled
- 351 Add SetHttpEnabled
UrlEncode
Parameters (1) | ||
---|---|---|
input | string | |
Returns (1) | ||
string |
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(), or POST
data of the media type application/x-www-form-urlencoded
(Enum.HttpContentType.ApplicationUrlEncoded).
For instance, when you encode the URL https://www.roblox.com/discover#/
,
this method returns https%3A%2F%2Fwww%2Eroblox%2Ecom%2Fdiscover%23%2F
.
Thread safety | Safe |
---|