What is API?
API (Application Programming Interface) is a particular set of rules (‘code’) and specifications that software programs can follow to communicate with each other. For example, you have a hardware button on your TV which turns it ON/OFF. Now suppose you want to turn ON the TV from a distance. You just press the ON/OFF button on a remote control and the TV set action on the command given by the remote control. This is how API works! Think of TV as a software program having services and resources, and the TV Remote control as another software program which use these resources. The method (or radio/infra red waves) through which a remote control communicates with a TV set is an API.
When and where it is used?
It’s used when 2 or more separate application need to work together to achieve something they can’t do alone.When interaction involve sending data over network, at that moment Web Service comes into the picture.
What is Web Service?
As the word sounds, they are not new fundamental business concept, it just a technology which permits old business concept to work together over the internet using some protocol. i.e. Oxford Dictionary API, in which you will send word, and in return it gives meaning of that word.
Modern web service communications are nearly always handled over HTTP. But the format of the message that are being sent and received can be different. Let’s consider one scenario for more understanding,
One service provider (A) is building application which shows latest designer clothes like amazon. For that he need to set up database to add products information (maybe it’s price, product name, images etc.) and one program to get that resources and display on application(Android, iOS, Web client) which is called as API call.
Note: Mark that this is limited to his application only, this will not allow other application to access his local data.