API stands for Application Program Interface. Its goal is to provide an interface so that other programs can send commands that will trigger some process inside the application, possibly returning some output. The concept might seem a bit abstract, but in fact, there are APIs virtually in everything which is somehow related to computers. Let's see some real life examples:
- Operating systems or OS, like Windows or Linux, are the programs that allow you to use computers. When you use any application from your computer, it most probably needs to talk to the OS in one way or another, for example by requesting a certain file, sending some audio to the speakers, and so on. All these interactions between the application and the OS are possible thanks to the APIs that the OS provides. In this way, the application need not interact with the hardware straight away, which is a very tiring task.
- To interact with the user, a mobile application provides a GUI. The interface captures all the events that the user triggers, like clicking or typing, in order to send them to the server. The GUI communicates with the server using an API in the same way the program communicates with the OS as explained earlier.
- When you create a website that needs to display tweets from the user's Twitter account, you need to communicate with Twitter. They provide an API that can be accessed via HTTP. Once authenticated, by sending the correct HTTP requests, you can update and/or retrieve data from their application.
As you can see, there are different places where APIs are useful. In general, when you have a system that should be accessed externally, you need to provide potential users an API. When we say externally, we mean from another application or library, but it can very well be inside the same machine.