Though APIs and web services can both facilitate data transfers between applications over the internet, they are not the same, and the terms should not be used interchangeably in every case. The key distinction is that web services are a type of API: All web services are APIs, but not all APIs are web services.
Web services are a type of API, which must be accessed through a network connection. REST APIs are a standardized architecture for building web APIs using HTTP methods.
There are four principal types of API commonly used in web-based applications: public, partner, private and composite. In this context, the API "type" indicates the intended scope of use.
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.
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:
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.
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"
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.
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.
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.
API is code based integration while web service is message based integration with interoperable standards having a contract such as WSDL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With