[][src]Static p5_sys::global::httpGet

pub static httpGet: HttpGetInternalType

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

// Examples use USGS Earthquake API:
//   https://earthquake.usgs.gov/fdsnws/event/1/#methods
let earthquakes;
function preload() {
  // Get the most recent earthquake in the database
  let url =
   'https://earthquake.usgs.gov/fdsnws/event/1/query?' +
    'format=geojson&limit=1&orderby=time';
  httpGet(url, 'jsonp', false, function(response) {
    // when the HTTP request completes, populate the variable that holds the
    // earthquake data used in the visualization.
    earthquakes = response;
  });
}

function draw() {
  if (!earthquakes) {
    // Wait until the earthquake data has loaded before drawing.
    return;
  }
  background(200);
  // Get the magnitude and name of the earthquake out of the loaded JSON
  let earthquakeMag = earthquakes.features[0].properties.mag;
  let earthquakeName = earthquakes.features[0].properties.place;
  ellipse(width / 2, height / 2, earthquakeMag * 10, earthquakeMag * 10);
  textAlign(CENTER);
  text(earthquakeName, 0, height - 30, width, 30);
  noLoop();
}

Overloads

path name of the file or url to load

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

data? param data passed sent with request

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

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


path name of the file or url to load

data param data passed sent with request

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

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


path name of the file or url to load

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

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