-: So we talked about the basic principles of what is an API
but another thing that is important to know about API
is that it comes in few flavors
and actually there are four main types of API.
The first type is Operating System API, next Library API
then Remote API, and last, Web API.
Let's dive deeper into each one of them
and explain what is it.
So Operating System API.
Let's say you write some kind of application.
It it doesn't really matter which platform
you are using to write this application
it can be .Net or Java or c++ or whatever.
Now, naturally, your application runs
inside an operating system.
Again, it doesn't matter which operating system.
iI could be Windows or Linux or OASIS or anything else.
In many cases, the application needs some kind of services
from the operating system.
For example, file system.
If the application wants to access files
in the operating system, it asks the operating system
to give it access to the files.
Network devices.
If the application needs to access network devices
connected to the operating system,
then the operating system should allow it.
User interface elements.
If the application, for example, wants to display a button
on the screen, then it asks the operating system
for a visual representation of the button.
So how does it do that?
How the application asks the operating system
for all those kind of services?
Well, the answer, as you probably guessed
is using the operating system API.
The operating system or the operating systems
exposed some kind of API
that applications that run in the operating system
can access and use.
And one of the most famous operating system API
is the win32 API.
It is used by all the applications that run on Windows
and it provides a huge number of operating system services.
Okay, next.
So the next type of API is the Library API.
And what it means is this.
When you develop your application,
you probably use some kind of libraries.
The concept of libraries is very common
in all the development platforms today.
So you develop your library, let's call it Users library,
and there is another library called Logging library.
Now the user library wants to use the logging library.
How can it do that?
Simply, the logging library exposes logging API,
and by doing so, it allows the user's library
to access this API and use logging library's method
such as right to log file or change the severity
of the logging or anything else.
But without an API, the users library
won't be able to access the logging library.
Now note again that those libraries
they are both executed in the same single process.
They are not communicating through any kind of network.
As mentioned earlier, class libraries are implemented in
all kinds of development platforms like
as we said, .NET, Java, Python, nodeJs
and even PHP and so on and so forth.
Okay, so the next type of API is Remote API.
Now what it means is this, we have two software components.
Let's say these are User component and Orders component.
Now note that those two components
are distributed over the network,
meaning they are not in the same process
and probably also not on the same server
or virtual machine or PC.
In order for them to communicate with each other
they need to go through the network.
So how do they do that?
So the User component build an Orders proxy.
This proxy is used to communicate with the Orders component.
This proxy contains all the internal working
of accessing the Orders component.
It knows everything there is to know about
how to access the component, such as
network protocol, network address, methods, signatures,
authentication, authorization, everything that is important
in order to access this component.
So after building this proxy, the Orders proxy
can access the Orders component using proprietary protocol
and access the method
and all the other functionality exposed by this component.
Now, what is important to know
about this method of communication, the remote API
is that in it mandates
that both the components will be based
on the same development platform.
For example, it's not possible in this example,
that the user component will be developed using .net
and the orders component will be developed in Python.
It'll simply won't work.
Examples of such a Remote API implementations are
DCOM, .NET Remoting, Java RMI, and there are some more.
Its also important to note that
Remote API is losing popularity
and almost no one is using them nowadays.
And that brings us to the last
and definitely not the least kind of API,
which is the Web API.
With Web API, web apps and web APIs
can communicate with each other over the internet
and here is how it works.
So we are looking at the internet
and we have some kind of web app
which we developed and published over the internet.
This web app wants to use another web apps, let's say
weather web app, which provides weather forecast
for destinations that we are interested in.
How can my web app communicate with the weather web app?
So there are a few steps for this.
First, the weather web app should expose, and again
not the use of the word expose.
It exposes Web API.
Then my web app can access this web API
and it can do it because the web API
always uses standard protocol for accessing it.
And using this protocol, my web app can access this web API
and query the weather web app for weather forecast.
Now, one of the most important thing to know
about the web API is that it can be used
across any platform, operating system, or language.
In other words,
it doesn't really matter how my web app is implemented
and how the weather web app is implemented.
If you remember, we say that we Remote API,
both the software components must be developed
using the same platform.
This is not the case with Web API.
In this example, my web app can be developed using .NET
and the weather web app can be developed using Java
and it'll work just fine.
This is just one of the factors that make Web API
so successful and so popular.