What is an API?
An API is not a database or web server. However, it provides secure access to both. When an application or client requests some information (data) to the API, the API redirects the request to the appropriate source and passes the received response to the client.
What API is and what does it doSo, what exactly is an API?
Interface is a core object oriented programming principle (OOP) used by many programming languages. Interface hides the implementation from outsiders (i.e., third-party applications and services), but still lets them use functions from an application. So, if you want to use a functionality, you’d know what the method does, but you wouldn’t know how the method works! The interface in an API is very similar—you hide the internal workings of your program by exposing only a part of the functionality through the API.
Why is it helpful?
By exposing an API, you provide a protocol that other programs can use to communicate with your app.
Let’s say you want to build an app where users can book slots for playing basketball, based on court availability. Since basketball is an outdoor sport, you want to display the weather so that it's handy for customers to make an informed booking. If there is already a weather application that displays weather based on your location and time, it’d save a lot of your effort building another one.
Now, if the person who created this weather app exposed a public API (say the method name), you can use their functionality as it is and get the data for your app users!
Example to show an API