API stands for Application Programming Interface
An API provides a set of functionality, it could be a function or a method that performs a specific task, a simple example could be a calculator program written in any language. One can use this API or calculator program by calling it’s function/method with appropriate parameters.
These are generally used to provide access to frequently used operations.
We can say, API is a contract between two systems [may not be developed using same language] to communicate, that contract defines the rules of how to use the services.
Example –
Individual aero plane service providers expose their APIs related to seat availability, cost and timings, and there are lots of 3rd party applications uses these APIs to list the seat availability all together in one browser screen for end users.
These 3rd party applications sends request as parameters [based on user selection on web site], and then service providers takes those requests and processes by using the APIs which in turn sends back the response.
How different a web service over API
Both API and web services are means of communication.
But web services involves communication over a network that is defined by W3C standard (a software system designed to support interoperable machine-to-machine interaction over a network) using http protocol.
Web service uses REST or SOAP or XML-RPC framework as means of communication, basically web services are APIs wrapped in http.
Web services exchange data by a specified format in either XML or JSON.
An API can use any form to communicate, e.g – even can communicate by using DLL / JAR files as well.
All web services are APIs, but all APIs are not web services.