API vs. Webservice [closed]

2019-01-09 22:48发布

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

9条回答
一纸荒年 Trace。
2楼-- · 2019-01-09 23:12

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.

查看更多
够拽才男人
3楼-- · 2019-01-09 23:17

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.

查看更多
倾城 Initia
4楼-- · 2019-01-09 23:21

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

查看更多
Juvenile、少年°
5楼-- · 2019-01-09 23:25

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.

查看更多
Evening l夕情丶
6楼-- · 2019-01-09 23:25

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).

查看更多
疯言疯语
7楼-- · 2019-01-09 23:26

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"

查看更多
登录 后发表回答