Java API 和 Web 服务有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4229567/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between API and web services?
提问by krunal shah
As per my knowledge api and web services are used to fetch data from other websites.
据我所知,api 和 web 服务用于从其他网站获取数据。
So what's difference between them ?
那么它们之间有什么区别呢?
Any Help!
任何帮助!
EDIT
编辑
Can somebody please explain it with proper example ?
有人可以用适当的例子解释一下吗?
What is twitter and facebook api ? Can we say it's just a function or webservices to access their data.
什么是推特和脸书 api?我们可以说它只是访问其数据的功能或网络服务。
回答by Justin Niessner
An API doesn't need to be web based.
API 不需要是基于 Web 的。
Web Services may also may not perform all of the operations one would expect from a full API.
Web 服务也可能无法执行人们期望从完整 API 中获得的所有操作。
回答by Edwin Buck
A web service is just an API in HTTP clothing.
Web 服务只是 HTTP 服装中的 API。
回答by winwaed
A web service is something delivered over the Internet for direct use by another computer (rather than a human).
Web 服务是通过 Internet 提供以供另一台计算机(而不是人类)直接使用的东西。
An API is an Application Programming Interface. A website application might expose an API thorugh a web service. However, desktop applications like Excel or Word have APIs which have nothing to do with the web (they have VBA and COM based APIs).
API 是应用程序编程接口。网站应用程序可能会通过 Web 服务公开 API。但是,Excel 或 Word 等桌面应用程序具有与 Web 无关的 API(它们具有基于 VBA 和 COM 的 API)。
Simlarly, a server application (eg. Joomla) might have a PHP based API that is used from withinthe server - ie. no web service necessarily involved.
类似地,服务器应用程序(例如 Joomla)可能有一个基于 PHP 的 API,可从服务器内部使用 - 即。不一定涉及网络服务。
回答by Mike Baranczak
A web service can be thought of as a type of API. But for the moment, you should forget that, and just concentrate on learning what an API actually is; a precise definition of methods for interacting with a piece of software. Sometimes, this involved sending data over a network, but usually we're talking about functions that may be called from a program.
可以将 Web 服务视为一种 API。但目前,你应该忘记这一点,专注于学习 API 究竟是什么;与软件交互的方法的精确定义。有时,这涉及通过网络发送数据,但通常我们谈论的是可以从程序调用的函数。
For example, there's a function called FileUtils.rm
in Ruby. This is the API; when you're calling the function from a Ruby script, it always looks the same. Then there's the implementation of the API; that's the code that actually removes the file - it might look completely different in every implementation of Ruby, but you (normally) don't care about that, since you're only dealing with the Ruby API.
例如,有一个FileUtils.rm
在 Ruby 中调用的函数。这是 API;当您从 Ruby 脚本调用该函数时,它看起来总是一样的。然后是 API 的实现;那是实际删除文件的代码 - 在 Ruby 的每个实现中它可能看起来完全不同,但您(通常)并不关心这一点,因为您只处理 Ruby API。
回答by iirekm
API (application programming interface) is a list of methods and classes exposed by a programmer to use by other programmers, so eg if you use Twitter or Facebook API in your programs, you can make it cooperate with Twitter and Facebook, and do many useful things. :-)
API(应用程序编程接口)是一个程序员暴露给其他程序员使用的方法和类的列表,所以例如如果你在你的程序中使用 Twitter 或 Facebook API,你可以让它与 Twitter 和 Facebook 合作,并做很多有用的事情事物。:-)
There are many ways of exposing APIs (JAR files or RMI in Java, .net Assemblies, COM objects, DLL and .H files in C/C++, JSON over HTTP, XML over HTTP, many home-made methods).
公开 API 的方式有很多种(Java 中的 JAR 文件或 RMI、.net 程序集、COM 对象、C/C++ 中的 DLL 和 .H 文件、HTTP 上的 JSON、HTTP 上的 XML、许多自制方法)。
Web Services are just yet another way of exposing API, in this case the actual execution of the exposed methods is done not on your computer, but on some other computer on the Internet (on the Web - hence name "WebServices").
Web 服务只是公开 API 的另一种方式,在这种情况下,公开方法的实际执行不是在您的计算机上完成,而是在 Internet 上的其他计算机上完成(在 Web 上 - 因此称为“WebServices”)。
回答by David Bressler
Check out the wikipedia entry on web API's at http://en.wikipedia.org/wiki/Api#Web_APIs.
在http://en.wikipedia.org/wiki/Api#Web_APIs上查看有关 Web API 的维基百科条目。
It's well written, though pretty much agrees with what the others here say.
写得很好,虽然几乎同意这里其他人所说的。
回答by Andrew Grimm
All web services are APIs, but not all APIs are web services. One is a subset of the other.
所有 Web 服务都是 API,但并非所有 API 都是 Web 服务。一个是另一个的子集。
回答by Madan
Webservices available over internet.you can get information without actually having the classes or know how it works using http and soap protocols.
可通过 Internet 获得的 Web 服务。您无需实际拥有课程即可获取信息,也无需了解使用 http 和soap 协议的工作原理。
API is a kind of library (set of classes), you can use the functions available in that to perform some action in your application.
API 是一种库(类集),您可以使用其中可用的函数在您的应用程序中执行某些操作。
回答by prady00
APIs exposed over web are Webservices
通过 Web 公开的 API 是 Web 服务
回答by Priyanka
- Web Service is an API wrapped in HTTP.
- All Web Services are API but APIs are not Web Services.
- Web Service might not perform all the operations that an API would perform.
- A Web Service needs a network while an API doesn't need a network for its operation.
- Web Service 是封装在 HTTP 中的 API。
- 所有 Web 服务都是 API,但 API 不是 Web 服务。
- Web 服务可能不会执行 API 将执行的所有操作。
- Web Service 需要网络,而 API 的操作不需要网络。