Reference httpGet()

httpGet()

Method for executing an HTTP GET request. If data type is not specified, p5 will try to guess based on the URL, defaulting to text. This is equivalent to calling httpDo(path, 'GET'). The 'binary' datatype will return a Blob object, and the 'arrayBuffer' datatype will return an ArrayBuffer which can be used to initialize typed arrays (such as Uint8Array).

Examples

Syntax

httpGet(path, [datatype], [data], [callback], [errorCallback])
httpGet(path, data, [callback], [errorCallback])
httpGet(path, callback, [errorCallback])

Parameters

path
String:

name of the file or url to load

datatype
String:

"json", "jsonp", "binary", "arrayBuffer", "xml", or "text"

data
Object|Boolean:

param data passed sent with request

callback
Function:

function to be executed after httpGet() completes, data is passed in as first argument

errorCallback
Function:

function to be executed if there is an error, response is passed in as first argument

Returns

Promise: A promise that resolves with the data when the operation completes successfully or rejects with the error after one occurs.
Notice any errors or typos? Please let us know. Please feel free to edit src/io/files.js and open a pull request!

Related References