Hi, Adrian, and welcome back.
Now, in today's video, we are going to discuss about the basics of application programming interface
referred to as API.
Now, before we discuss the advantages that the API provides, let's look into a simple challenge that
will allow us to understand the advantages.
So let's assume that you have a book distributor, and this distributor maintains the list of available
books in its backend system, and there is an operator that is working for this distributor and this
operator has access to this backend system through which he can check the availability of the books
and the clients.
They generally connect to the specific operator via a phone call or chat option to understand the availability
of books.
So if you have to look into this from the diagrammatic perspective, it would look something similar
to this where you have some kind of a backend system, you have your operator here and you have a client.
Now operator has access to the backend system through which he can check the list of available books
and clients.
Since they do not have access to the backend system, they connect with the operator to check the availability.
Now, from this specific architecture, you can understand the challenges that this operator as well
as the clients would face for each of the books.
They'll have to contact the operator.
And if you have thousands of clients, this type of approach is not scalable.
So what you might want is you want the clients to have access to the backend system, but you do not
really want that.
Also because the backend system might have sensitive data as well, and if clients run some random command
on the system, it can also break the overall application.
So in order to overcome this, you can make use of an API.
So the book distributor could provide an API to check the stock availability.
So there is an API here.
The clients can send the data to the API.
API will in turn connect with the backend system to check the availability and then the response will
be sent back to the client.
So at a high level overview, the API lets you open access to your resource while maintaining the security
and control.
So at this stage the clients do not directly have access to the backend system.
However, there is an intermediary layer through which the connections work.
Now, at this intermediary layer of API, you can add a lot of security controls, you can add cache,
you can add authentication, you can add a web application firewall, you can do some kind of a request
throttling and so on.
So everything you can do at the API level and you can also configure the API to accept only certain
type of requests.
For example, not all of the requests will be allowed, but only the request to check the availability
of a certain book will be allowed through API.
So let's do one thing to better understand things in more detail practically as well.
Let's take a simple use case.
So the use case states that James wants to build a weather report application.
It can be Android, iOS application and to build a weather report application, you need to fetch data
from somewhere because there are so many areas across the world.
So there is a website called Open Weather Map, which is an online service that provides the global
weather data via the API.
Now again, note that this data is provided via the API.
So what James does, he decides to connect his application to the open Weather Map API to fetch the
latest reports and populate it in its application.
So maybe James can build some kind of a graphics, which makes things easier for the users to understand
what is going on.
So let's go ahead and look into this from a practical point of view.
Now, if you look into the open weather map, you see that the weather of Mumbai is 29 degrees Celsius,
which is quite good.
And it is also giving you the forecast of next eight days.
Apart from that, this specific website also allows you to search weather of different countries and
cities.
For example, let's try London.
Let's look into what is the weather there.
So the weather is five degrees Celsius.
And not only this, you have an hourly forecast, you have an eight day forecast.
So at this stage, we understand that James, as an individual developer, he will not be able to create
all of these forecasts and get weather across all of the countries.
So he decides to make use of the open weather.
Now, open weather provides certain set of APIs through which James can connect to fetch the data.
So if you look over here, let's look into the API section.
Now, depending upon the API, there are certain feature sets that are available.
So you have one API version 3.0.
With this you get a minute forecast for one hour and so many others.
You also have a pricing associated with this in case you prefer to.
Now for today's demo, I already have an API key that I have created.
So if you look over here, this is the API key.
So through this API key I can connect to the open weather to fetch the data.
So let's go ahead and try it out now from the CLI.
If you make a call request to the API of the open weather map and within your I have also specified
the API key.
Now if I press enter, you get a specific response over here and based on the response that James receives,
he can go ahead and build appropriate set of charts.
Now apart from that, there are a lot of interesting use cases where you can make use of the API.
For example, in this specific website through the API, if you see through the API, you can scan a
certain document.
So if you're not aware, if this document has malware or some kind of a malicious activity through the
API, you can go ahead and verify if the document is safe or not.
Now, in the real world, environment APIs are extensively used specifically for the use cases where
two softwares wants to communicate with each other.
So for example, James Weather Report application wants to communicate with the open weather map.
So these are two softwares that wants to communicate with each other.
So this is where also APIs are used very heavily.
So this is a very high level overview on what APIs are and with this will conclude today's video.