The Mystery of API

·

4 min read

Have you ever heard the word “API” batted about and wondered exactly what this is? Do you have a vague idea but want to know more about the wonders of API…

Don’t fret. I can help!

Let’s get down to it and pick apart what an API is and learn about its importance. Also in addition, I am going to briefly introduce you to JSON and XML.

What is an API?

API stands for Application Programming Interface. An API defines how two pieces of software talk to each other.

Let me give you a simple example. Assume that you are using Instagram app on your mobile phone and want to view someone’s post. The app sends an ‘API request’ to Instagram server with data that recognizes you and then, asks for the requested information. The server in return, sends back an ‘API response’ which contains the required data.

So whenever a developer builds something that uses an API, they should know:

  • What the request looks like so that the server can understand it.

  • What the response looks like so that they can make sense of the data.

💡
The first web API was created by ‘eBay’.

Importance of API

Now imagine you are building an app which lets users find out dog parks near to their place. For this, you will have to consider several APIs provided by the cities which give a list of all the dog parks. Then, your app will also take the help of API provided by Google Maps to help the user reach his/her destination with the help of directions. Hence, your app will first call the city API, then the Google API and finally lead the user to the closest dog park.

This is how by using APIs, apps can mash data from different sources together.

💡
ProgramableWeb.com is a website which keeps a track of all web APIs that are publicly available to use.

What is JSON

JSON stands for JavaScript Object Notation and is a programming language. Originally created to hold the structured data to be used in JavaScript, now, it is being used for data of all kinds of applications.

JSON is the most popular way of sending data for web APIs. It uses array which is a type of data structure.

We know that in an array, the values are separated by comma and are enclosed within square brackets. An array is a kind of list where values can be of mixed data types.

Example: [65, ”red”, true, 21, null]

JSON also uses dictionary but here, it is known as an Object. An object is enclosed in curly brackets. Keys and values are separated by colon and each pair is separated by a comma.

Though, keys and values can be any data type, string is the most common data type.

Example: {“red”:205, “green”:123}

JSON Code:

This code has two objects, one nested in another. JSON ignores whitespaces and to make the code readable, we use indentations.

What is XML?

XML stands for eXtensible Markup Language. XML have tags which work like HTML. However, the tag names must only be letters, numbers and underscores.

Example: <artist>The Beetle</artist>

If the content has no tags, then it is treated like a string, even though it has no quotes. You can put tags inside another tag to create nested data.

The first line of an XML file is known as XML Declaration.

Comments in XML start with <!-- and end with -->. XML files can be described with a schema called XSD (XML Schema Definition).

So I hope you got a clarity on what API is and understood the basic concepts of JSON & XML. If you found this blog interesting and informative.. do drop a ❤️ and I'll see you next Saturday with a new blog on a new topic. Till then,

Learn, Share, Grow!

Click me to connect on X!