abhinesh ch
abhinesh ch

Reputation: 39

Difference between api and web service?

In many questions, people have explained the difference between an API and a web service. I know it's a means of communication between service provider and service consumer, but both look the same as serving to me: the consumer sends a request and gets a response in return from the provider.

  1. If that is so what is it that really makes them different?

  2. Why do we have two different terms, both web service and API?

Upvotes: 3

Views: 4995

Answers (4)

iSensical
iSensical

Reputation: 757

All answers above are perfectly fine, consider one short note -

API = connecting with some other code (internal [without network] or external [with network] )

API over HTTP = Web Service

Upvotes: 4

Phillip Neiman
Phillip Neiman

Reputation: 31

I think this is a great answer from user Buh Buh here on April 12, '13:

At a low level web applications and web services are kinda the same thing. They both operatate over http(s). SOAP is just a well defined version of XML. REST is kinda just HTTP. If you wanted to, you could make a web application look like web services and visa versa.

The main difference would be internal development options based on the platform you are using. If, for example, you are using Visual Studio then adding a WCF Service Application will give you a project which is by default geared towards WCF. But choosing any other application type won't stop you from adding Web Services.

Using SOAP is generally a better option than plain old xml for these reasons:

  • Your users will be expecting it, and are likely to know how to read it already.
  • Your users' development environments will likely know all about SOAP and be able to interpret it out of the box. (If you provide a WSDL file then many users will be able to use a script to generate your classes in seconds.)
  • Your messages are more likely to be well defined. I am working on a project at the moment where the other side have defined their own random XML structure and it is a nightmare to work with. I never really know what to expect, and there is little consistency between their different message types. At least if they had agreed to conform to SOAP then I might have had a much easier time interpreting their messages.

Upvotes: 3

andyg0808
andyg0808

Reputation: 1403

An API is not necessarily web-based. It's really just a specification of how to talk to someone else's work using a programming language. A web service, on the other hand, is one example of someone else's work which a program will talk to using an API.

In the case of a web service, an API might specify how to communicate over the web to the service, in order to use it. Frequently, however, the communication protocol for a service will not be described directly. Instead, the API will be a specification of how to use a client library provided by the service author. A good example of both of these is the Google Maps API. Google provides both a specification of how to request data from their service via HTTP (a web service API) and a client library in Javascript which can be used to request the same thing.

But this is not the only possible use of the term API. jQuery (which is a Javascript library, but not a remote web service) also refers to its documentation as API Documentation. Similarly, the Wikipedia page on API gives the example of the POSIX standard for operating systems.

In short, an API is a specification, while a web service is one example of a system which can be documented with an API.

Upvotes: 3

snit80
snit80

Reputation: 731

An API need not be a Web Service at all (Although in the web world it is more likely that an API is a web service). An API could be for Hardware for Database connectivity etc.

Upvotes: 1

Related Questions