WEBVTT

00:00.000 --> 00:05.920
Consuming public APIs In today's connected world,

00:05.920 --> 00:11.040
many applications rely on public APIs to access and share information.

00:11.040 --> 00:14.720
A public API is an interface made available by a service.

00:14.720 --> 00:20.800
For example, open weather map or Google Maps that allows developers to retrieve or send data.

00:23.520 --> 00:25.200
Imagine you're building a weather app.

00:25.840 --> 00:28.480
Instead of storing global weather data yourself,

00:28.480 --> 00:32.560
you can use the open weather map API to get real-time information directly.

00:33.360 --> 00:37.360
To use a public API, developers read the API documentation,

00:37.360 --> 00:41.360
which explains the endpoints, parameters, and how to authenticate requests.

00:42.880 --> 00:49.680
In short, public APIs make it possible to access data and services from other platforms safely and efficiently.

00:51.120 --> 00:55.920
Some APIs are open to everyone, but many require authentication to keep data secure.

00:55.920 --> 01:03.040
When an API requires authentication, you'll often need to register and obtain an API key,

01:03.040 --> 01:06.080
a unique code that identifies you as a user.

01:06.080 --> 01:10.320
Think of an API key as a digital access card.

01:10.320 --> 01:14.000
It lets you in, but also keeps track of how you use the data.

01:14.000 --> 01:20.800
It's important to store API keys securely, never hard-coding them directly into public repositories,

01:20.800 --> 01:22.160
or code shared online.

01:22.800 --> 01:26.240
This helps protect both your account and the data you access.

01:26.240 --> 01:31.600
So, before using an API, always check if you need a key and follow the instructions to keep it safe.

01:35.840 --> 01:39.680
Once you have access, you can make requests to the API to get data.

01:40.480 --> 01:45.520
Most APIs use HTTP methods like Get to retrieve data.

01:46.800 --> 01:49.200
Post to send or update data.

01:49.920 --> 01:53.360
In programming, you can use different libraries to make these requests.

01:54.320 --> 02:01.200
In Java, developers use HTTP URL connection, or OK HTTP.

02:02.320 --> 02:05.440
In Python, the request module is most common.

02:06.080 --> 02:09.200
This short code retrieves the current weather description for London.

02:13.840 --> 02:17.840
When working with APIs, it's important to check if your request was successful.

02:18.640 --> 02:20.640
Every response comes with the status code.

02:21.440 --> 02:22.800
200 means success.

02:23.360 --> 02:25.760
400 means not found.

02:26.480 --> 02:29.280
And 500 indicates a server error.

02:30.640 --> 02:33.360
Always handle these responses gracefully.

02:33.360 --> 02:36.560
For example, showing a friendly message instead of crashing the app.

02:38.160 --> 02:40.720
Timeouts or connection issues can also happen,

02:40.720 --> 02:43.040
so your code should handle errors carefully.

02:43.520 --> 02:47.680
From checking weather and navigation to reading online news,

02:48.480 --> 02:50.640
APIs make all of this possible.

02:50.640 --> 02:57.520
By learning how to consume public APIs, use API keys, make requests, and handle errors,

02:57.520 --> 03:02.640
you're taking the first step toward becoming a confident developer in today's data driven world.

