Webrequest

Summary

Functions to call remote websites or APIs

Class Methods

WebRequest:Get(url, onSuccess, onError, headers, context)

Sends a GET request to the given URL

Returns: nil

Parameters:

NameTypeDefaultDescription

url

string

The URL to send the request to

onSuccess

function

A function to call when the request succeeds

onError

function

A function to call when the request fails

headers

table

A table of key-value pairs to send as headers

context

table

A value to pass to the onSuccess and onError functions

Example

WebRequest:Get("https://www.example.com/", onSuccess, onError, {["Accept"] = "application/json"}, context)

WebRequest:Post(url, postData, onSuccess, onError, headers, context)

Sends a POST request to the given URL with the given data

Returns: nil

Parameters:

NameTypeDefaultDescription

url

string

The URL to send the request to

postData

table

A table of key-value pairs to send as POST data

onSuccess

function

A function to call when the request succeeds

onError

function

A function to call when the request fails

headers

table

A table of key-value pairs to send as headers

context

table

A value to pass to the onSuccess and onError functions

Example

WebRequest:Post("https://www.example.com/", {["foo"] = "bar"}, onSuccess, onError, {["Accept"] = "application/json"}, context)

Last updated