What is the difference between a webservice and an API? Is the difference more than the protocol used to transfer data? thanks.
-
3By API, you mean an API accessed by HTTP? Or just a regular plain API? – Pablo Santa Cruz Apr 30 '09 at 18:37
-
See also: [What is the difference between a web API and a web service?](http://stackoverflow.com/questions/19336347) – hippietrail Mar 28 '14 at 14:06
-
1See also programmers.SE: [Difference between Web API and Web Service?](http://programmers.stackexchange.com/questions/38691) – hippietrail Mar 28 '14 at 14:06
-
You've gotta be kidding me. 122 upvotes and the question is broken due to mixing levels. – Joshua Mar 21 '16 at 16:09
-
you got me, I'm not sure why this question was closed – chips Mar 24 '16 at 19:22
9 Answers
An API (Application Programming Interface) is the means by which third parties can write code that interfaces with other code. A Web Service is a type of API, one that almost always operates over HTTP (though some, like SOAP, can use alternate transports, like SMTP). The official W3C definition mentions that Web Services don't necessarily use HTTP, but this is almost always the case and is usually assumed unless mentioned otherwise.
For examples of web services specifically, see SOAP, REST, and XML-RPC. For an example of another type of API, one written in C for use on a local machine, see the Linux Kernel API.
As far as the protocol goes, a Web service API almost always uses HTTP (hence the Web part), and definitely involves communication over a network. APIs in general can use any means of communication they wish. The Linux kernel API, for example, uses Interrupts to invoke the system calls that comprise its API for calls from user space.

- 1,052
- 2
- 18
- 30

- 4,392
- 3
- 26
- 27
-
8Would you consider every web service as being API? How about when using AJAX to reload a region of a web page as opposed to reloading the entire page? I do not necessarily see this as being API even though a web service is involved. Otherwise, we can make a case that for every bit of function ever created, be it in a DLL, or JAR, web service, or plain code to be all APIs. For an API to be API it has to have 3rd party developers in mind and the API should have no dependency whatsoever with the final product (the app that is using the API). – Ronald Nov 11 '13 at 04:49
-
19Yes, every Web Service is an API. Yes, an AJAX Web Service is an API, it's just undocumented and therefore not really meant for public consumption. Not every API is an API designed for 3rd party consumption. You can have internal APIs too. – Ryan Shillington Jul 23 '14 at 19:45
Basically, a webservice is a method of communication between two machines while an API is an exposed layer allowing you to program against something.
You could very well have an API and the main method of interacting with that API is via a webservice.
The technical definitions (courtesy of Wikipedia) are:
API
An application programming interface (API) is a set of routines, data structures, object classes and/or protocols provided by libraries and/or operating system services in order to support the building of applications.
Webservice
A Web service (also Web Service) is defined by the W3C as "a software system designed to support interoperable machine-to-machine interaction over a network"
-
4I'm OK with someone objecting to my answer but I'd be curious to know why. – Mark Biek Apr 30 '09 at 18:46
-
41Your response implies that APIs and Webservices are distinct, when in fact a web service is a type of API. Since the crux of this question is what's the difference between the two, it's important for the response to clarify that webservices are a type of API. – Andrew Cholakian Apr 30 '09 at 19:21
-
3Interesting. I'm going to have to (respectfully :) ) disagree. But I do appreciate the feedback. – Mark Biek Apr 30 '09 at 19:34
In a generic sense an webservice IS a API over HTTP. They often utilize JSON or XML, but there are some other approaches as well.

- 41,026
- 12
- 101
- 131
-
20
-
13Right, APIs can be libraries such as DLLs, JARs or OCX etc.. They can also be a source code distribution such as Facebooks' PHP api... – cgp Apr 30 '09 at 20:06
API's are a published interface which defines how component A communicates with component B.
For example, Doubleclick have a published Java API which allows users to interrogate the database tables to get information about their online advertising campaign.
e.g. call GetNumberClicks (user name)
To implement the API, you have to add the Doubleclick .jar file to your class path. The call is local.
A web service is a form of API where the interface is defined by means of a WSDL. This allows remote calling of an interface over HTTP.
If Doubleclick implemented their interface as a web service, they would use something like Axis2 running inside Tomcat.
The remote user would call the web service
e.g. call GetNumberClicksWebService (user name)
and the GetNumberClicksWebService service would call GetNumberClicks locally.

- 46,440
- 34
- 114
- 174
-
This question is really old, but I'll note that this answer confuses APIs and interfaces. An API is more than a published interface (which would include things like SOAP), it's the public interface to a particular application or service. It'd be more accurate to say something like "API's are components that have a published interface by which third-party components may interact with them." – JDB Jan 10 '13 at 02:07
API(Application Programming Interface), the full form itself suggests that its an Interface which allows you to program for your application with the help or support of some other Application's Interface which exposes some sort of functionality which is useful to your application.
E.g showing updated currency exchange rates on your website would need some third party Interface to program against unless you plan to have your own database with currency rates and regular updates to the same. This set of functionality is when already available with some one else and when they want to share it with others they have to have an endpoint to communicate with the others who are interested in such interactions so they deploy it on web by the means of web-services. This end point is nothing but interface of their application which you can program against hence API.

- 95
- 2
- 7
API is code based integration while web service is message based integration with interoperable standards having a contract such as WSDL.

- 39
- 1
Think of Web service as a web api. API is such a general term now so a web service is an interface to functionality, usually business related, that you can get to from the network over a variety of protocols.

- 10,273
- 8
- 40
- 56
Check this http://en.wikipedia.org/wiki/Web_service
As the link mentioned then Web API is a development in Web services that most likely relates to Web 2.0, whereas SOAP based services are replaced by REST based communications. Note that REST services do not require XML, SOAP, or WSDL service-API definitions so this is major different to traditional web service.

- 1,218
- 1
- 13
- 20
another example: google map api vs google direction api web service, while the former serves (delivers) javascript file to the site (which can then be used as an api to make new functions) , the later is a Rest web service delivering data (in json or xml format), which can be processed (but not used in an api sense).

- 27
- 1
-
1Uhm...javascript can be returned as data and then used as code, this is not a valid contrast – David C May 31 '12 at 18:42