Reference httpDo()

httpDo()

Method for executing an HTTP request. If data type is not specified, p5 will try to guess based on the URL, defaulting to text.

For more advanced use, you may also pass in the path as the first argument and a object as the second argument, the signature follows the one specified in the Fetch API specification. This method is suitable for fetching files up to size of 64MB when "GET" is used.

Examples

Syntax

httpDo(path, [method], [datatype], [data], [callback], [errorCallback])
httpDo(path, options, [callback], [errorCallback])

Parameters

path
String:

name of the file or url to load

method
String:

either "GET", "POST", or "PUT", defaults to "GET"

datatype
String:

"json", "jsonp", "xml", or "text"

data
Object:

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

options
Object:

Request object options as documented in the "fetch" API reference

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