Created
May 2, 2019 18:25
-
-
Save trevorblades/f183b5ddf9835931b85851a5766d1150 to your computer and use it in GitHub Desktop.
fornite app notes
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
<!-- | |
use getUserStats as the form's submit handler | |
so that users can press "enter" in the text input | |
--> | |
<form onsubmit="getUserStats"> | |
<input type="text" name="username"> | |
<button type="submit"> | |
</form> |
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
// define the common parts of the API url as a variable so we don't need to rewrite it every time | |
const baseUrl = 'https://fortnite-public-api.theapinetwork.com/prod09'; | |
function getUserStats(event) { | |
// to prevent the regular form submit behavior | |
event.preventDefault(); | |
// grab the value of the form field named "username" | |
const username = event.target.username.value; | |
// start fetching! | |
fetch(`${baseUrl}/users/id?username=${username}`) | |
.then(resp => resp.json()) | |
.then(data => fetch(`${baseUrl}/users/public/br_stats_v2?user_id=${data.uid}`)) | |
.then(resp => resp.json()) | |
.then(stats => { | |
console.log(stats); | |
}) | |
.catch(error => { | |
console.log('request failed', error); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment