DEV Community

Cover image for Difference between API and Web Service
Chhotu
Chhotu

Posted on

Difference between API and Web Service

Let's see what definitions says.

  • API (Application Programming Interface) is a software interface that permits two applications to interact directly with each other without any user intervention.
  • Web service is a collection of some open protocols and standards which are used to exchange data between systems or applications.
    Now Let's understand the differences between them.

Web services and APIs are two of these overlapping tech terms that often get confused. you would possibly have even heard these words used interchangeably, but are they even an equivalent thing?

Here is the answer:
An API is an interface that permits you to build on the data and functionality of potentially another application, while a web service is a network-based resource that fulfills a specific task.
Yes, they overlap on each other: all web services are APIs, but not all APIs are web services.

Contrary to what you would possibly think, APIs and web services aren't mutually exclusive. One is a subset of the other: every web service is an API — since it exposes an application’s data and it's functionality — but not every API is a web service. this is often because the definition of a web service is sort of restrictive when it involves implementation:

  • Web services require a network. While APIs can be offline or online, web services must use a network.
  • APIs are generally protocol agnostic. Web services usually use SOAP (but sometimes REST, UDDI, and XML-RPC), whereas APIs can use any protocols or design styles.

API vs WebServices

Some of the key differences are:

  • API is used for any style of communication, whereas Web service is used for only REST, SOAP and XML-RPC for communication.
  • API supports both HTTP and HTTPS protocol, whereas Web service supports only HTTP protocol.
  • API supports XML and JSON, whereas Web service only supports XML.

Top comments (4)

Collapse
 
andreidascalu profile image
Andrei Dascalu

Sorry but the API definition is wrong.

An API is a programatic interface that allows a developer to interact with a system.

APIs are the sum of functions that can be called by a user of that system (eg: what you can use to "program").

Example:

  • the PHP API is the sum of functions exposed by the PHP core (as listen on PHP.net docs)
  • any library provides an API: the public functions and objects you can use to integrate and make use of that library
  • your own objects have an API, etc

Sure, there are many kind of APIs, some are web APIs (REST or SOAP ) but most aren't

Collapse
 
chhotu05 profile image
Chhotu

Hey Andrei, thanks for your comment But you are narrowing down the definition of an API by considering the case of only "calling the set of function by developer and users". What you are saying is absolutely correct but there is more to API.
Remember All Web services are API but vice-versa is not true

Collapse
 
andreidascalu profile image
Andrei Dascalu

Actually I'm expanding the definition, not narrowing it down. I said it's the set of functions that are exposed. Doesn't matter the exact definition of who calls them as long as they are used to program something.

I actually underlined that very fact, not all API are web which is why I gave the example of what the PHP language API is or what a class API is ( the public methods other devs can call) which is an example of just that: API that is NOT a web service.

Thread Thread
 
chhotu05 profile image
Chhotu

I got your point !! thanks