Difference between API and Web Service

Profile picture for user devraj

Web Service and API are related concepts, but they have some distinctions:

Point of DistinctionAPIWeb Service
1. DefinitionAn API, or Application Programming Interface, is a set of definitions and protocols that allow one application to communicate with another application.A Web Service is type of API or subset of API that speficially uses HTTP protocol. A web service is either: a service offered by an electronic device to another electronic device, communicating with each other via the Internet, or a server running on a computer device, listening for requests at a particular port over a network, serving web documents (HTML, JSON, XML, images).
2. Need of NetworkAPIs can be online or offlineWeb services are accessed through a network connection only.
3. TypeAll APIs are not web services. All Web Services are API because it exposes an application's data and/or functionality. In other words, A web service is just an API wrapped in HTTP.
4. Light Weight ArchitectureAPIs have lightweight architecture and are suitable for limited bandwidth devices, like mobile devices. Web Services require SOAP protocol to send and receive data over the network, so it is not lightweight architecture.
5. Style of CommunicationAPIs are used for any style of communication.Web services usually use SOAP (but sometimes REST, UDDI, and XML-RPC).
6. ProtocolAPIs provide support for the HTTP and HTTPS protocolsWeb Services only support the HTTP protocol
7. Support for XML or JSONAPIs XML and JSON and other data formats.Commonly use XML or JSON for data exchange.
8. Open SourceMany APIs are open source and publicly available with documentation and can be used by the client that understands XML or JSON. Web Services are not open source but can be used by any client that understands XML. They tend to offer specific data and/or functionality to particular partners.
9. CompressionIn API, Data can be compressed.Web Services uses HTML requests that can be compressed, but XML data cannot be compressed.
10. SpecificationsAn API is a complete set of rules and specifications that follow to facilitate the interaction.Web Services does not have a complete set of specifications, and sometimes it cannot perform all the functions that the API can execute.

Video Tutorial: Web Services vs API