The first thing we're going to explore is how to authenticate ourselves with an
API provider so that we can access more secure and more valuable data from the
API providers. Up to this point, we've learned about API endpoints,
so figuring out what is the URL that we need to hit up in order to get a
particular piece of data. We also looked at API parameters,
so passing in different inputs so that we can get different pieces of data
back from the API provider.
Now we're going to take one step further and look at how we can use APIs
that require authentication. Previously
all of the APIs that we've used were free APIs.
They were provided completely free and we can access all parts of it without any
sort of payment here. Now,
this is because the data that's contained in those APIs are very simple and
nobody is going to be using that data to build a very fancy or big commercial
application. Now, on the other hand, there's
other types of data that are very valuable, for example, weather data,
because it
makes a lot of energy and time for somebody or some company to collect all of
this data and provide it for you. In these cases,
some of these APIs can have a paid tier.
So you actually have to pay if you're running an application
or if you have a company that needs to get this data very frequently and you
need to get large amounts of the data.
Why do people charge for API anyways? Well, if you think about something simple
like the weather, it's not actually that simple. How do you even get
the weather
if I asked you to figure out the weather without using some sort of website or tool?
Well, in this particular case, open weather map,
they have access to over 4,000 weather stations across the globe,
and then their data scientists will take that weather data and look at the
satellite images and process that data in order to figure out the weather and
predict the weather for each city in the world. As you can imagine,
that's going to be really resource-intensive and it's going to require a lot of
employees and also server maintenance and electricity costs, right?
So for all of that hassle, if they're going to provide this data for you,
then it's reasonable that you should be paying for it, right?
Essentially you can see a lot of
APIs as a way of selling data.
If you own some sort of privileged piece of data that you are constantly
updating, or you are actively generating, for example,
weather data from satellite images or financial data,
then it's reasonable that you should be charging for this data
especially if somebody is going to rely on it heavily in order to build a
commercial app or a company. But luckily,
most of these APIs provide a free tier that allows you to test out the
application.
And if you are somebody who's just learning the ropes then it doesn't make sense
to charge you.
It only makes sense when your application or your service has a lot of users.
And then you start going into the paid tiers. Now,
how do you prevent people from abusing this free tier?
Because anybody can say, well, I'm just learning, you know.
You can be somebody who's running a 1000 employee company
and you could claim that you're just learning.
So the way that they prevent people from abusing their service is through
something known as an API key.
And this is almost like your personal account number and password.
This is the way how the API provider can track how much you're using their API
and to authorize your access and deny you access
once you've gone over the limit. Now,
different API providers tend to have different ways that you can authenticate
yourself with them,
but most of them involve some sort of an API key.
In the next lesson, I want to show you how we can implement the open weather
map API,
authenticate ourselves with an API key that we generate, and get the live wather
data. So for all of that and more, I'll see you on the next lesson,