Skip to content

Latest commit

 

History

History
67 lines (31 loc) · 2.2 KB

File metadata and controls

67 lines (31 loc) · 2.2 KB

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
urlstringThe URL to send the request to
onSuccessfunctionA function to call when the request succeeds
onErrorfunctionA function to call when the request fails
headerstableA table of key-value pairs to send as headers
contexttableA 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
urlstringThe URL to send the request to
postDatatableA table of key-value pairs to send as POST data
onSuccessfunctionA function to call when the request succeeds
onErrorfunctionA function to call when the request fails
headerstableA table of key-value pairs to send as headers
contexttableA value to pass to the onSuccess and onError functions

Example

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