Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

It stands for Application Programming Interface.

It's a way for someone to set up a way to access a


certain body of information.

An easy example is the Star Wars API. If I wanted to make a website about Star Wars, instead of finding
and creating all the data myself, I could build a website that focuses on pulling data from an existing Star
Wars API.

So I could have a search feature with parameters like "planet", "date", "ship", "allegiance", etc.

If someone wanted to find a list of characters from a desert planet named Tatooine, they could choose
that from a dropdown and then run the search.

My website would take that "tatooine" parameter, ask the Star Wars API for info that matches the
"key":"value" pair of "planet":"tatooine", and then deliver those results back to the user's computer
through my website.

Those "key": "value" pairs are the sets of data within an API. The "value" could be a string, number,
array, object, etc. So you could have a very simple API like this:

"friend1": [

"name": "john smith",

"age": 50,

"children": false

],

"friend2": [

"name": "sarah sanders",

"age": 40,

"children": ["toby", "ashley", "sam"]

That data would be saved as a JSON file. Let's pretend the file is named "friends.json". Then we can
access that data with something like:

console.log(friends["friend1"].name()); // This would give back "john smith"


API can get pretty complex and deeply nested, so you'll often wind up exporting sets of API data into
variables for easier use. Instead of something like:

console.log(starWarsAPI.ships["millenium falcon"].pilot.preferredWeapons())

You could do something like:

let milleniumFalcon = starWarsAPI.ships["millenium falcon"]

And then access it with:

console.log(milleniumFalcon.pilot.preferredWeapons())

I don't actually know the Star Wars API and all of the above was just made up as an example.

You might also like