HttpService
HttpService : Instance
Overview
Provides HTTP request feature used to communicate with external web services. With this feature, a variety of features such as analytics system integration, cloud-based data processing, external server environment application, or real-time data transfer can be integrated into game world.
In addition, when communicating with API in JSON format, data can easily be serialized or deserialized with the JSONEncode and JSONDecode methods.
It is recommended to send HTTP requests only to trusted and secure external platforms in order to maintain a stable and safe world environment.
Properties
HttpEnabled
bool
A setting used to allow communication with external web services through HttpService.
If this value is set true, HTTP requests can be sent to external servers in script using the GetAsync, PostAsync, and RequestAsync methods.
This option can also be enabled in the studioβs Game Settings menu.
Code Samples
local HttpService = game:GetService("HttpService")
print(HttpService.HttpEnabled)Methods
GenerateGUID
It generates an UUID string only once in the entire execution environment; any subsequent calls return the same UUID.
The generated identifier expresses 16-byte data into 32 hexadecimal characters, makes them in the form of 8-4-4-4-12, and provides them in a 36-character string (123e4567-e89b-12d3-a456-426655440000 for example).
Parameters
bool bInWrapInCurlyBraces
Whether or not to include the curly brackets enclosing a string (default: false).
Return
string
The generated UUID.
Code Samples
GetAsync
A simple way to transfer an HTTP GET request, it behaves similarly to RequestAsync, but it sends requested information as individual factor and returns only the body of response data.
If the value of NoCache is set true, it transfers a new request to server every time instead of using the cache of requests sent to the same address in the past.
Parameters
string InUrl
The URL of a web server to send request.
bool InNoCache
Whether or not to use cache (default: false).
Value InHeaders
The header information to be included in HTTP request.
Return
string
The data returned by server in response to GET request.
Code Samples
JSONDecode
Converts objects or arrays in JSON into a Lua table.
The JSON object is a table based on string keys; the JSON array is converted into an array of number keys starting from 1.
All numbers are interpreted as a float value and nesting structures are converted into recursive structures.
An empty JSON object or array is returned as an empty table.
Parameters
string InInput
The JSON data to be converted.
Return
Value
The converted Lua table data.
Code Samples
JSONEncode
Converts Lua table into JSON object or array.
The value nil is not included in JSON; special numbers such as inf and nan are converted as well, but because they are not JSON standard, there may be a compatibility issue when integrating external systems.
An empty table is converted into an empty JSON array and if there is a circular reference in a table, an error occurs during conversion.
Parameters
Value InInput
The Lua table data to be converted.
Return
string
The data in converted JSON.
Code Samples
PostAsync
Performs HTTP POST requests. It provides features similar to those of the RequestAsync() function, but it can transfer requested data in individual variable instead of a single dictionary and returns only the body instead of the entire response.
It is often used for light coding. It is better to use the RequestAsync() function instead in most situations.
In addition, if the compress option is set true, the body of a large request is automatically compressed in gzip for more efficient transfer.
Parameters
string InUrl
The URL of a web server to send request.
string InData
The data to be transferred.
Enum.HttpContentType InContentType
Transfer format (default: ApplicationJson) can be specified by adjusting the header value of Content Type.
bool InCompress
Whether or not to compress data in gzip when transferring data to server (default: false).
Value InHeaders
The header information to be included in HTTP request.
Return
string
The response data for POST request returned by server.
Code Samples
RequestAsync
Sends an HTTP request using any method with the provided dictionary of information.
Parameters
Dictionary InRequestOptions
Return
Value
Code Samples
UrlEncode
μ λ ₯λ λ¬Έμμ΄ λ΄μ μμ½ λ¬Έμλ₯Ό % κΈ°νΈμ λ μ리 16μ§μ μ½λλ‘ λ³ννμ¬, URLμμ μμ νκ² μ¬μ©ν μ μλ νΌμΌνΈ μΈμ½λ©(percent-encoding) λ¬Έμμ΄μ μμ±ν©λλ€.
Parameters
string InInput
The string (address) to be converted.
Return
string
The converted string (address).
Code Samples
Events
See also
JSON and HTTP CommunicationLast updated