The httpGet() function in p5.js is used to execute an HTTP GET request. The datatype returned is automatically guessed by p5 based on the URL, when it is not specified.
The data could be loaded in the preload() function so that it can be accessed immediately in the program.
httpGet( path, [datatype], [data], [callback], [errorCallback] )
httpGet( path, data, [callback], [errorCallback] )
httpGet( path, callback, [errorCallback] )
Parameters: This function accepts five parameters as mentioned above and described below.
- path: It is a string that denotes the path of the URL or file to load.
- datatype: It is a string that specifies the type of data that will be recieved. It can have the values of “json”, “jsonp”, “binary”, “arrayBuffer”, “xml”, or “text”. Using the ‘binary’ datatype will return a Blob object and using ‘arrayBuffer’ will return a typed array. It will default to ‘text’ is no parameter is specified. It is an optional parameter.
- data: It is an Object or a Boolean value that specifies the parameter data passed with the request.
- callback: It is a function which is called when this function executes successfully. The first argument for this function is the data returned from the API. It is an optional parameter.
- errorCallback: It is a function which is called if there is any error in executing the function. The first argument for this function is the error response. It is an optional parameter.
Return Value: It returns a promise that can be resolved with the data when the operation completes successfully, or be rejected when an error takes place.
Below examples illustrate the httpGet() function in p5.js:
Online editor: https://editor.p5js.org/
- How to get the function name inside a function in PHP ?
- PHP | Ds\Set last() Function
- p5.js | box() Function
- D3.js | d3.sum() function
- PHP | Ds\Set first() Function
- D3.js | d3.mean() function
- PHP | next() Function
- PHP | dir() Function
- D3.js | d3.map.set() Function
- PHP | Ds\Set contains() Function
- D3.js | d3.set.has() Function
- PHP | exp() Function
- p5.js | arc() Function
- PHP | Ds\Map put() Function
- PHP | pi( ) Function
- PHP | Ds\Map get() Function
- CSS | url() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.