forked from schen9981/cs1300-js-students
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1eaee6e
commit 28b0ddb
Showing
1 changed file
with
21 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,31 @@ | ||
var corsApiUrl = 'https://cors-anywhere.herokuapp.com/'; | ||
var corsApiUrl = "https://cors-anywhere.herokuapp.com/"; | ||
// TODO: REPLACE YOUR TOKEN | ||
var apiToken = '?token=ZAWafueiwitra0tTaAR2QzY3054rfHOgvv47pBG8Dug'; | ||
var apiToken = "?token=YOUR_TOKEN_HERE"; | ||
|
||
// fetches the data from the API endpoint | ||
// CORS stands for "cross origin resource sharing" -- you'll be making http requests in order | ||
// DON'T CHANGE THIS: fetches the data from the API endpoint | ||
const doCORSRequest = (options) => { | ||
var x = new XMLHttpRequest(); | ||
x.open("GET", corsApiUrl + options.url); | ||
x.send(options.data); | ||
return x; | ||
} | ||
}; | ||
|
||
// creates the promise | ||
const corsPromise = () => new Promise((resolve, reject) => { | ||
const request = doCORSRequest({ url: "https://trefle.io/api/v1/plants" + apiToken }); | ||
resolve(request); | ||
}) | ||
|
||
//// TODO: ADD WHATEVER FUN CONTENT YOU WANT //// | ||
// Example promise that executes the GET request above and waits for it to finish before resolving | ||
const corsPromise = () => | ||
new Promise((resolve, reject) => { | ||
const request = doCORSRequest({ | ||
url: "https://trefle.io/api/v1/plants" + apiToken, | ||
}); | ||
resolve(request); | ||
}); | ||
|
||
// THIS IS SOME SAMPLE CODE FOR HOW TO USE PROMISES -- feel free to adapt this into a function! | ||
corsPromise().then(request => request.onload = request.onerror = function () { | ||
// TODO: ADD FUNCTION, ETC. FOR WHATEVER YOU WANT TO DO ONCE THE DATA IS RECEIVED | ||
}); | ||
corsPromise().then( | ||
(request) => | ||
(request.onload = request.onerror = function () { | ||
// TODO: ADD FUNCTION, ETC. FOR WHATEVER YOU WANT TO DO ONCE THE DATA IS RECEIVED | ||
}) | ||
); | ||
|
||
//// TODO: ADD WHATEVER FUN CONTENT YOU WANT //// |