Skip to content

Commit fd7fa9f

Browse files
authored
Merge pull request #2164 from austince/docs/http-do
docs/httpDo
2 parents 7c70a38 + 2591538 commit fd7fa9f

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/io/files.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,56 @@ p5.prototype.httpPost = function () {
805805
* @param {function} [errorCallback] function to be executed if
806806
* there is an error, response is passed
807807
* in as first argument
808+
*
809+
*
810+
* @example
811+
* <div>
812+
* <code>
813+
* // Examples use USGS Earthquake API:
814+
* // https://earthquake.usgs.gov/fdsnws/event/1/#methods
815+
*
816+
* // displays an animation of all USGS earthquakes
817+
* var earthquakes;
818+
* var eqFeatureIndex = 0;
819+
*
820+
* function preload() {
821+
* var url = 'https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson';
822+
* httpDo(url,
823+
* {
824+
* method: 'GET',
825+
* // Other Request options, like special headers for apis
826+
* headers: { authorization: 'Bearer secretKey' }
827+
* },
828+
* function(res) {
829+
* earthquakes = res;
830+
* });
831+
* }
832+
*
833+
* function draw() {
834+
* // wait until the data is loaded
835+
* if (!earthquakes || !earthquakes.features[eqFeatureIndex]) {
836+
* return;
837+
* }
838+
* clear();
839+
*
840+
* var feature = earthquakes.features[eqFeatureIndex];
841+
* var mag = feature.properties.mag;
842+
* var rad = mag / 11 * ((width + height) / 2);
843+
* fill(255, 0, 0, 100);
844+
* ellipse(
845+
* width / 2 + random(-2, 2),
846+
* height / 2 + random(-2, 2),
847+
* rad, rad
848+
* );
849+
*
850+
* if (eqFeatureIndex >= earthquakes.features.length) {
851+
* eqFeatureIndex = 0;
852+
* } else {
853+
* eqFeatureIndex += 1;
854+
* }
855+
* }
856+
* </code>
857+
* </div>
808858
*/
809859

810860
/**

0 commit comments

Comments
 (0)