Object MethodNetwork and Integration

Request.patch(url)

Sends a PATCH request to the HTTPS address and returns a response object with getResponseCode() and getData(). It takes only the address; for headers or a body create a request object with Request(url).

Documented for app version 1.0.51Updated:

Detailed Explanation

This section explains when to use the API, how to call it, and which structures it works best with in production flow.

How To Call It

This is a function of the Request factory table itself: call it with a dot (Request.<method>(...)); no Request object is needed. An object method with the same name also exists: request:patch(...).

When To Use It

For network integration, use HTTPS only, keep the response size bounded, and validate the response code before moving into JSON or File steps.

Parameters and Return

Required: url. Returns a response object with getResponseCode() and getData().

Options and Limits

Limits: only HTTPS addresses are accepted; a request body may be up to 1 MB and a response up to 5 MB; connect and read time out after 10 and 15 seconds (at most 60 seconds with setTimeout); setRetry makes at most 4 attempts. Request calls are limited to 30 per second. On the response object getResponseCode() returns the HTTP status and getData() the body text.

Best Combined With

The most common pattern is to check a Request response with getResponseCode(), read its body with getData() and parse it with JSON.parse().

Example Usage

The snippet below is a starter pattern that can be applied directly in runtime flow.

local response = Request.patch("https://example.com/api/status")
if response:getResponseCode() == 200 then
  local data = JSON.parse(response:getData())
end

Copyable Progressive Examples

From foundation to combined usage, each level is provided as a separate code block so you can copy the level you need and adapt it directly.

Foundation

Shows the shortest direct way to call the API.

Foundation
local response = Request.patch("https://example.com/api/status")
if response:getResponseCode() == 200 then
  local data = JSON.parse(response:getData())
end

Simple

Wraps the base call with minimal flow control.

Simple
local stepOk = true
local response = Request.patch("https://example.com/api/status")
if response:getResponseCode() == 200 then
  local data = JSON.parse(response:getData())
end
if stepOk then
  wait(200)
end

Practical Flow

A practical pattern for real macros with pcall, logging, and guards.

Practical Flow
local ok, err = pcall(function()
  local response = Request.patch("https://example.com/api/status")
  if response:getResponseCode() == 200 then
    local data = JSON.parse(response:getData())
  end
end)

if not ok then
  print("API step failed: Request.patch: " .. tostring(err))
  requestStop()
end

Detailed

This level packages the API into a reusable helper with error reporting.

Detailed
-- For network integration, use HTTPS only, keep the response size bounded, and validate the response code before moving into JSON or File steps.
local function run_patch_step()
  local response = Request.patch("https://example.com/api/status")
  if response:getResponseCode() == 200 then
    local data = JSON.parse(response:getData())
  end
end

local ok, err = pcall(run_patch_step)
if not ok then
  toast("Step failed")
  print(err)
end

Combined

Combines the API with related structures to form a more realistic workflow.

Combined
-- POST a JSON body: Request.post(url) takes no body, so configure a request object
local request = Request("https://example.com/api/scores")
request:setContentType("application/json")
request:setBody(JSON.stringify({ level = 3, score = 1200 }))
local response = request:post()
if response:getResponseCode() == 200 then
  print(response:getData())
else
  print("HTTP " .. tostring(response:getResponseCode()))
end