Creator Guide
English
English
  • OVERDARE
    • 🚩Introduction to OVERDARE
    • 🐤Get Started
      • OVERDARE App
      • OVERDARE Studio
    • 📌Policy
      • Community Guidelines
      • UGC Creation Guidelines
      • Guidelines on the External Use of UGC
      • Logo Usage Guidelines
      • Intellectual Property Rights Policy
      • Reporting Guidelines
      • Guidelines on Disputing Suspensions and Bans
      • Creator Payout Policy
      • Monetization Guidelines
      • Forum Guidelines
    • 🅰️OVERDARE Glossary
  • MANUAL
    • 🏰Studio Manual
      • Get Started
        • Studio Interface
        • World Template
        • Coordinate System
        • Studio Test Play
        • World Publish
        • Collaboration
      • Asset & Resource Creation
        • Asset Import
        • Animation Editor
        • Setting Shadow Detail
      • Game Development
        • Game Settings
        • Script Editor
        • Align Tool
        • Material Manager
        • Collision Groups
        • Tag Editor
        • Performance Guide
        • World Performance Analytics
      • Object
        • Part
        • Model
        • Camera
        • Physics
        • Lighting
        • Tool
        • VFX
        • Sound
      • Character
        • Character Animation
        • Humanoid Description
      • GUI
    • 📝Script Manual
      • Get Started
        • Script Overview
        • Basic Guide to Lua
        • Coding Style
        • Object Reference
        • Unity Developer Guide
      • Events & Communication
        • Event
        • Server-Client Communication
        • BindableEvent
        • Value Objects
      • Input & Controls
        • Mobile Input Handling
        • TPS Strafing System
      • Advanced Gameplay Systems
        • Saving & Loading Data
        • Tween
        • Module Script
        • JSON and HTTP Communication
      • Debugging & Optimization
        • Breakpoint
        • Practical Guide to Script Optimization
    • 💡Creator Reference Materials
      • Game Term Translation Guide for Creators
    • 💸Monetization
      • Payout Guideline
  • DEVELOPMENT
    • 📚API Reference
      • Enums
        • ActuatorRelativeTo
        • AnimationPriority
        • AspectType
        • AssetTypeVerification
        • BorderMode
        • CameraMode
        • CameraType
        • ContextActionResult
        • CoreGuiType
        • DominantAxis
        • EasingDirection
        • EasingStyle
        • ForceLimitMode
        • HttpCompression
        • HttpContentType
        • HumanoidDisplayDistanceType
        • HumanoidStateType
        • KeyCode
        • Material
        • MaterialPattern
        • NormalId
        • ParticleEmitterShape
        • ParticleEmitterShapeInOut
        • ParticleEmitterShapeStyle
        • ParticleFlipbookLayout
        • ParticleFlipbookMode
        • ParticleOrientation
        • PartType
        • PlaybackState
        • RaycastFilterType
        • RollOffMode
        • RotationType
        • UserInputState
        • UserInputType
        • VelocityConstraintMode
      • DataTypes
        • BlendSpaceSampleSata
        • BrickColor
        • CFrame
        • Color3
        • ColorSequence
        • ColorSequenceKeypoint
        • Content
        • Enum
        • EnumItem
        • NumberRange
        • NumberSequence
        • NumberSequenceKeypoint
        • OverlapParams
        • PhysicalProperties
        • Ray
        • RaycastParams
        • RaycastResult
        • ScriptConnection
        • ScriptSignal
        • TweenInfo
        • Udim
        • Udim2
        • Vector2
        • Vector3
      • Classes
        • Animation
        • AngularVelocity
        • AnimationTrack
        • Animator
        • Atmosphere
        • Attachment
        • Backpack
        • BackpackItem
        • BasePart
        • BaseScript
        • Beam
        • BindableEvent
        • BlendSpace
        • BoolValue
        • Bone
        • Camera
        • CharacterMesh
        • CollectionService
        • Constraint
        • ContextActionService
        • CoreGui
        • DataStore
        • DataModel
        • DataStoreGetOptions
        • DataStoreIncrementOptions
        • DataStoreInfo
        • DataStoreKeyPages
        • DataStoreKeyInfo
        • DataStoreService
        • DataStoreListingPages
        • DataStoreSetOptions
        • FormFactorPart
        • Frame
        • Folder
        • GlobalDataStore
        • GuiBase2d
        • GuiButton
        • GuiObject
        • HttpService
        • Humanoid
        • HumanoidDescription
        • ImageButton
        • ImageLabel
        • InputObject
        • IntValue
        • LayerCollector
        • Instance
        • Light
        • Lighting
        • LinearVelocity
        • LocalScript
        • LuaSourceContainer
        • MaterialService
        • MaterialVariant
        • MeshPart
        • Model
        • ModuleScript
        • Mouse
        • NumberValue
        • OrderedDataStore
        • Pages
        • Part
        • ParticleEmitter
        • PhysicsService
        • Player
        • PlayerGui
        • Players
        • PlayerScripts
        • PointLight
        • PVInstance
        • ReplicatedStorage
        • RemoteEvent
        • ScreenGui
        • RunService
        • Script
        • ServerStorage
        • ServiceProvider
        • Skeleton
        • ServerScriptService
        • Sound
        • SoundService
        • SoundGroup
        • SpotLight
        • SpawnLocation
        • StarterCharacterScripts
        • StarterPack
        • StarterGui
        • StarterPlayer
        • StarterPlayerScripts
        • StringValue
        • SurfaceGui
        • SurfaceGuiBase
        • Team
        • Teams
        • TextLabel
        • TextButton
        • Tool
        • Trail
        • Tween
        • TweenService
        • TweenBase
        • UIAspectRatioConstraint
        • UserGameSettings
        • UserInputService
        • UserSettings
        • VectorForce
        • Workspace
        • WrapLayer
        • WorldRoot
        • WrapTarget
  • UPDATE
    • 📰Release Note
Powered by GitBook
On this page
  • Overview
  • How to Use
  • Receiving a response from the URL
  • Sending JSON Data to the URL to Receive a Response
  • Using JSON Data Received from the URL
  • Note
  1. MANUAL
  2. Script Manual
  3. Advanced Gameplay Systems

JSON and HTTP Communication

Overview

You can communicate with external HTTP servers using HttpService. You can retrieve data from an external API server to use in the world, or send data to an external API server and use the response data in the world.

How to Use

Function
Description

GetAsync(url)

Receives a response from the URL

PostAsync(url, data)

Sends data to the URL and receives a response

JSONEncode(tableData)

Converts tableData in the table format into a JSON string and returns it

JSONDecode(json)

Converts JSON in the JSON format into a table format and returns it

Receiving a response from the URL

This is an example code that sends an HTTP GET request to the URL provided in the baseUrl variable, stores the response in the response variable, and prints it.

-- Imports HttpService
local HttpService = game:GetService("HttpService")
local baseUrl = "Enter the HTTP URL here"

local success, errorMessageOrResult, response = nil, nil, nil

local function HttpGet()
    -- Handles exceptions with pcall() as asynchronous requests can fail or encounter errors
    success, errorMessageOrResult = pcall(function()
        -- Sends an HTTP GET request to the "baseUrl" address and stores the response in the "response" variable
        response = HttpService:GetAsync(baseUrl)
    end)
    
    local messageSuccess = string.format("success: %s", success)
    local messageErrorOrResult = string.format("errorMessageOrResult: %s", errorMessageOrResult)
    local messageResponse = string.format("response: %s", response)
    
    print("messageSuccess: ", messageSuccess)
    print("messageErrorOrResult: ", messageErrorOrResult)
    print("messageResponse: ", messageResponse)
end

Sending JSON Data to the URL to Receive a Response

This is an example code that encodes table data used in the world to JSON, sends an HTTP POST request to the URL specified in the baseUrl variable, stores the response in the response variable, and prints it.

-- Imports HttpService
local HttpService = game:GetService("HttpService")
local baseUrl = "Enter the HTTP URL here"

local success, errorMessageOrResult, response = nil, nil, nil

local function HttpPost()
    -- Defines data to send to the URL
    local data = 
    {
        ["message"] = "Hello OVERDARE!",
        ["data"] = 10,
    }

    -- Encodes data to JSON
    local jsonData = HttpService:JSONEncode(data)

    -- Handles exceptions with pcall() as asynchronous requests can fail or encounter errors 
    success, errorMessageOrResult = pcall(function()
        -- Sends an HTTP POST request with "jsonData" to the "baseUrl" address and stores the response in the "response" variable 
        response = HttpService:PostAsync(baseUrl, jsonData)
    end)

    local messageSuccess = string.format("success: %s", success)
    local messageErrorOrResult = string.format("errorMessageOrResult: %s", errorMessageOrResult)
    local messageResponse = string.format("response: %s", response)
    
    print("messageSuccess: ", messageSuccess)
    print("messageErrorOrResult: ", messageErrorOrResult)
    print("messageResponse: ", messageResponse)
end

Using JSON Data Received from the URL

This is an example code that sends an HTTP GET request to the URL provided in the baseUrl variable, stores the response in the response variable, decodes the response (assuming it is JSON) into a table, and prints it.

-- Imports HttpService
local HttpService = game:GetService("HttpService")
local baseUrl = "Enter the HTTP URL here"

local success, errorMessageOrResult, response = nil, nil, nil

local function HttpGetApplication()
    -- Handles exceptions with pcall() as asynchronous requests can fail or encounter errors
    success, errorMessageOrResult = pcall(function()
        --Sends an HTTP GET request to the "baseUrl" address and stores the response in the "response" variable
        response = HttpService:GetAsync(baseUrl)
        -- Decodes the JSON string into a table and stores it in the "response" variable 
        response = HttpService:JSONDecode(response)
    end)

    local messageSuccess = string.format("success: %s", success)
    local messageErrorOrResult = string.format("errorMessageOrResult: %s", errorMessageOrResult)
    local messageResponse = string.format("response.data: %s", response.data)
    
    print("messageSuccess: ", messageSuccess)
    print("messageErrorOrResult: ", messageErrorOrResult)
    print("messageResponse: ", messageResponse)
end

Note

There may be rate limits, API calls per minute, for each API address. Make sure to check the request limits of the API address when implementing your desired functionality.

PreviousModule ScriptNextDebugging & Optimization

Last updated 1 day ago

📝