views:

1814

answers:

5
+6  Q: 

API vs. Webservice

What is the difference between a webservice and an API? Is the difference more than the protocol used to transfer data? thanks.

+3  A: 

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"

Mark Biek
I'm OK with someone objecting to my answer but I'd be curious to know why.
Mark Biek
Your 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
Interesting. I'm going to have to (respectfully :) ) disagree. But I do appreciate the feedback.
Mark Biek
+1  A: 

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.

Joshua Belden
+1  A: 

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.

altCognito
So all webservices are API but not all API's a webservice?
chips
Right, APIs can be libraries such as DLLs, JARs or OCX etc.. They can also be a source code distribution such as Facebooks' PHP api...
altCognito
+16  A: 

An API is an Application Programming Interface, it's the means by which third parties can write code that interfaces with other code. A Web Service is a type of API, almost always one that 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 otherwise mentioned.

For examples of web services specifically see SOAP, REST, and XML-RPC

As 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 protocol goes, a Webservice 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 userspace.

Andrew Cholakian
+1  A: 

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.

nzpcmad