What is an API?
An API is a messenger that takes your request, delivers it to a server and returns the response to you.
How does it work?
Imagine you are at a restaurantβ¦
The menu (contract) tells you what is available to order (request).
You submit your order through the waiter (API) who delivers it to the chef (server).
The chef uses certain ingredients (database info) to assemble your request and prepare it for the waiter to return to you.
When are they used?
The iOS Weather app uses the Weather Channel API to deliver forecasts.
Google Maps uses the Uber API to allow users to order rides in-app.
Websites use it when they if people want to sign in/up with a third-party like Google or Facebook (AKA single sign-on/SSO).
Yelp uses a Google Maps geocoding API to convert restaurant addresses into geographic coordinates and pin them on a map.
Tinder uses a Facebook API to access user info like age, gender and friends and allow users to create an account in one tap.
Why are APIs important?
With a line of code, developers can outsource work and integrate powerful features like hailing a cab or enabling financial transactions. APIs allow easy access to info, reduce complexity, perform tasks and increase functionality.
What is the contract and why is it important?
API developers create a contract in the documentation. Users must follow the guidelines in order for the API to successfully communicate with the server and return the requested data.
If the contract rules are violated, the API wonβt return the data and the app may crash. This makes APIs secure, because it will only expose pre-approved data. For example, a web app will not share an entire database or private user info like passwords; it will return only necessary info like log-in pages.