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
0 parents
commit 1eaee6e
Showing
3 changed files
with
39 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
var corsApiUrl = 'https://cors-anywhere.herokuapp.com/'; | ||
// TODO: REPLACE YOUR TOKEN | ||
var apiToken = '?token=ZAWafueiwitra0tTaAR2QzY3054rfHOgvv47pBG8Dug'; | ||
|
||
// 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 //// | ||
|
||
// 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 | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<title>CS1300 JavaScript Studio</title> | ||
<!-- <script src="https://unpkg.com/axios/dist/axios.min.js"></script> --> | ||
<link rel="stylesheet" href="styles.css"> | ||
</head> | ||
|
||
<body> | ||
<!-- TODO: ADD HTML FOR WHATEVER YOU WANT TO SHOW ON THE PAGE! --> | ||
</body> | ||
<script src="app.js"></script> | ||
|
||
</html> |
Empty file.