Web Service and API are related concepts, but they have some distinctions:
Point of Distinction | API | Web Service |
---|---|---|
1. Definition | An 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 Network | APIs can be online or offline | Web services are accessed through a network connection only. |
3. Type | All 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 Architecture | APIs 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 Communication | APIs are used for any style of communication. | Web services usually use SOAP (but sometimes REST, UDDI, and XML-RPC). |
6. Protocol | APIs provide support for the HTTP and HTTPS protocols | Web Services only support the HTTP protocol |
7. Support for XML or JSON | APIs XML and JSON and other data formats. | Commonly use XML or JSON for data exchange. |
8. Open Source | Many 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. Compression | In API, Data can be compressed. | Web Services uses HTML requests that can be compressed, but XML data cannot be compressed. |
10. Specifications | An 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. |