User blog:SpeedoThreeSixty/Using the A Minecraft Struggle API

= Notability =

I don't really think too many people know about my for . Well, let's dive right into it!

= Feel at Home with the A Minecraft Struggle API =

There are two links that you really need to know:


 * 1) https://glitch.com/edit/#!/a-minecraft-struggle, for learning more about what's up with everything sent from the
 * 2) https://a-minecraft-struggle.glitch.me/, the beginning of the URL to get data from the

Go ahead and click the 1st link above. Keep it open in another tab while we do these things, we'll be using it later to understand the data sent back from the.

Now, before we begin, I'll tell you that there are 2 types of complete URLs to receive actually-useful data from the :



For now, let's try using the 1st type of complete URLs!

Go ahead and finally click on the 2nd link all the way above. Yay, we got some actually-useful data! ... Right? Of course not!

This is because we did not supply any information, thus the yields us an empty page titled, well, "Untitled"!

As of writing this, there are two s that are available:



Let's choose the  of. With the "s"! I'll tell you why later (here's a hint: "<3").

Currently, we have the following semi-complete URL:

As of writing this, there are two s under the   of   that are available:



Just because I like myself and you should like me too <3, let's choose the  of. Not just "speedo", and without the ".json"!

Great! Go ahead, in that page that sadly just says "Untitled", click on the address bar, then type  to the end of it and press "Enter". Optionally, you could also close that "Untitled" page and go to this link:

https://a-minecraft-struggle.glitch.me/players/speedothreesixty

Please note that these URL types are not case-sensitive. This link would yield the same results:

HTTPS://A-Minecraft-Struggle.Glitch.Me/Players/SpeedoThreeSixty

That's the beauty of all this!

So, now, you have something called "JSON GET Response Data". You probably don't understand some of it. Go back to the Glitch link you opened before that I said explained more about this and give it a read!

Let's go on to how to use this "JSON GET Response Data" within your own Node.js code!

= Implementing the A Minecraft Struggle API into your Node.js Code =

I Neither Understand nor Have Node.js! Help?

 * 1) You can download Node.js at https://nodejs.org/en/download/current/.
 * 2) You can check if Node.js was successfully installed by executing  and   in your terminal.
 * 3) You can read more docs about Node.js at https://nodejs.org/dist/latest-v15.x/docs/api/.

Setup & Installing the npm Package
Execute these commands in your terminal if you haven't already:



Now, you should be in the folder inside of your favorite text editor.

Create a new file named. Your text editor should automatically go to that new file.

Copy and paste the code below into that file:

// const fetch = require("node-fetch") async function getJSON(url, property) { // const responseJSON = await fetch(url.toString).then(res => res.json) if (property) { // return responseJSON[property] } else { // return responseJSON }   }    const BASE_AMS_API_URL = "https://a-minecraft-struggle.glitch.me/" // * // * "AMS" stands for "A Minecraft Struggle"

Now we have a function that will get "JSON GET Response Data" from a website, typically an API, and a constant variable that we can use to get data from the.

Go back to your terminal and execute the following commands:



Note: You can instead run  if you wish to specify your own   details for your project.

Wait for npm to say that the  npm package was successfully installed, and then you can change the following lines of code in that file as follows:


 * to
 * to
 * to
 * to

To wrap it all up, you can use this new function by using this code:

const myData = await getJSON(`${BASE_AMS_API_URL} / `, myProperty)

OR:

const myData = await getJSON(`${BASE_AMS_API_URL} `, myProperty)

Note:  is essentially useless as an HTML webpage cannot be transferred into "JSON GET Response Data".