什么是Web?Web Service、Web API傻傻分不清楚?

前言

分享一篇我在edx课程中看到的一篇英文文章,这篇文章详细阐述了Web、Web Server的含义,然后进一步介绍什么是Web API、Web Server、SOAP以及RESTFUL Web API的一些基础概念。本文根据个人的理解对原文进行了翻译,限于我的知识水平,若有翻译不到位的地方还请批评指正。

正文

Web究竟是什么意思?

如今,网络十分普及。运行在不同电脑上的软件可以互相“对话”。软件们进行交流时所使用的语言称之为“协议”(protocols)。比如你可能听说过的TCP、HTTP以及FTP协议。

Web其实就是在某一网络中的一组计算机,它们通过HTTP协议进行交流。Web可大可小,比如:

  • 在公司的内网中,如果有一些计算机通过HTTP协议交流,借助Web浏览器分享文件,那它们构成的是一个小型网络(SMALL Web)。

  • 在互联网(the Internet)上,数以亿计的电脑和设备通过HTTP协议组成了一个大型网络(BIG Web)。事实上,它是地球上最大的东西之一,即万维网(the Would Wide Web)。

什么是网络服务器(Web Server)?

通常,当软件通过网络进行交流的时候,每个软件程序所扮演的角色可能是不同。如果一个程序持有某些资源,例如数据或者一组逻辑指令,此外,它还能提供这些资源给其他程序,便可将该程序以及运行该程序的电脑称之为服务器(Server),即服务提供者。相反,如果一个程序没有它所需要的资源,不得不向网络中的其他程序请求资源,我们可以将它称之为客户端(Client

当程序通过网络来提供数据或者计算资源(computing power,直译为计算能力,但显得有些生硬,此处我译为计算资源,表示计算机它所能提供的计算能力)的时候,便称之为Web服务器(Web server)。因为在网络上的计算机/设备是通过HTTP协议相连接的,我们可以轻松的推断出:网络服务器必须通过HTTP协议提供或者暴露自身所持有的资源。

网络服务器能够提供给客户端的资源是庞大的,但是总体上我们能分成两类:数据计算资源。服务器上数据的表征形式很多,比如HTML页面、PNG 图像、MP3/MP4文件或者在数据库中的一连串记录。计算资源是指服务器所能提供的计算能力,而服务器的计算性能通常要比客户端强很多,当然这取决于客户计算机上的硬件条件。

通过请求,客户端可以向服务器发送参数,在服务器接受参数并且执行某些计算以后,将通过一个响应(response)返回相应的结果给客户端。

  • 如果网络服务器提供数据资源,并且数据是HTML格式的(我们知道浏览器能够渲染HTML编写的页面),我们称这个网络服务器的资源为站点(Website)。

  • 如果网络服务器提供数据资源,并且数据被序列化成XML、JSON或者其他格式,我们将它称之为数据网络服务(Data Web service)或者数据服务(Data Service)

  • 如果一个网络服务器提供计算资源,这意味着客户端可以远程调用网络服务器上的计算资源,并且网络服务器将以合适的格式返回计算结果,我们称这类网络服务器为网络服务(Web Services)或者网络API(Web API)

正如你所注意到的,无论资源的类型是什么,都必须在给客户端的响应(response)中包含一些结果或者数据。这些结果数据证明了服务器上资源的存在性,我们称这些数据是资源的表征形式(representataion)

什么是Web API?

API表示应用程序接口(Application Programming Interface),它对使用类库中的成员而言是极其重要的。如果你想成功地使用类库中的成员,你必须遵守由这些类库开发者定义的API。

在引用类库以后,应用程序能够轻易地在单个计算机中调用或使用类库中的功能。实际的问题是应用程序和类库不在同一电脑上。那我们怎样才能在客户端的电脑上调用另一台电脑上的API呢?

对于这个问题有很多解决方案,例如远程过程调用(RPC, Remote Procedure Call)、公共对象请求代理体系结构(CORBA,Common Object Request Broker Architecture)等等。最终,开发者将远程调用嫁接到网络服务器上。这导致类库寄宿在网络服务器上并且通过HTTP协议暴露类库中的接口。

通过这种方式网络服务器可以集中计算资源并将它发布成网络服务(Web Services),客户端就可以远程使用服务器上的计算资源了。因为客户端仍然在调用类库中的API,只不过是通过网络(the web)远程地使用,我们称这种类型的网络服务为Web API。简而言之,如果一个网络服务作为一个类库的外包装,将其封装起来,并且仅仅提供远程调用计算资源的功能,我们就可以称其为Web API。

有很多方式和规则可以设计这些Web API:

  • 简单对象访问协议(SOAP, Simple Object Access Protocol)为表示远程服务调用和响应提供了一种约定。如果一个网络服务遵守SOAP约定,我们就成该网络服务为SOAP网络服务或者SOAP网络API(SOAP Web Service or SOAP Web API)。

  • 表征状态转移(Representational state transfer, REST)是一组针对网络应用程序设计的框架约束(不是一个协议或某种标准)。因为网络服务也是一种网络程序,我们可以将REST约束应用到网络服务的设计中。一旦一个网络服务遵守了REST的概念,我们就可将其称为RESTful网络服务或者RESTful网络应用程序接口RESTful Web Service or RESTful Web API)。

这与我们将一个局部变量简单地称呼为变量,将一个参数变量称呼为参数一样,我们总是将SOAP网络服务( SOAP Web Service)简称为网络服务(Web Service),将RESTful网络服务(RESTful Web Service)简称为Web API。这暗示大多数现代的Web API倾向于适应REST概念作为他们的设计原则。

至于REST是什么,那就敬请期待微信公众号以及CSDN上后续的文章推送了。

英文原文

What is the Web?

NOTE: This content is at a very basic level. You may skip this topic if you are already familiar with these concepts.

Nowadays, networking and the Internet are very popular. Software running on different computers can "talk" to each other. The "languages" used by software to "talk" are protocols. You may have heard about protocols such as TCP, HTTP, FTP, etc.

The Web is a group of computers in a network, and they communicate with each other through HTTP protocol, typically. The Web can be big or small, for example:

  • On an intranet of a company, if there are some computers that communicate with each other through HTTP and share documents via a web browser, that can be considered a SMALL web.

  • On the Internet, billions of computers and devices communicate through HTTP, forming a BIG web. As a matter of fact, it is one of the largest things on the Earth - the World Wide Web.

What is a Web Server

Usually, when software is communicating across a network, the role of each software application may be different. If an application holds the resources, such as data or program logic, and can provide these resources to other applications, we refer to the application, and the computer, as a server. In contrast, if the application does not have the resources it needs, it has to request the resources from other applications through the network. We call this role a client.

If an application can provide data and/or computing power across a web, we call it a web server. Because the computers/devices on a web are connected by HTTP protocol, we can easily infer that a web server must provide/expose resources through HTTP protocol.

There are a variety of resources the web server can provide to the web clients, but we can categorize resources into just two categories - data and computing power. Data can be represented by many things on the server, such as an HTML page, a PNG image, an MP3/MP4 file or a bunch of records in a database. Computing power means the computing ability of a server. Servers can typically offer greater computing resources than a client may possess, depending on the computer hardware used.

The client can send parameters to the server through requests. After the server accepts the parameters and executes a computation of some sort, it returns the result back to the client through a response.

  • If a web server provides data resources, and the data are in HTML format (we know a browser can render HTML content), we call this web server resource a Website.

  • If a web server provides a data resource, and the data is serialized in XML, JSON or other formats, we call this a Data Web Service or Data Service.

  • If a web server provides computing power resources, which means the web client can invoke the computing power on the web server remotely, and the web server will respond with the computing result (in proper format), we call this web server Web Services or Web API
    As you may notice, regardless of the type of resources, there must be some result or data in the response to the client. The result data proves the existence of resources on the server, and we call these data the representation of resources.

What is Web API

API stands for Application Programming Interface. An API is critical for referencing and invoking members in class libraries. If you want to use the members in class libraries successfully, your code must comply with the API defined by the developer of those class libraries.

After referencing a class library, the application can easily call or utilize the functionality of the class library on a single computer. The real problem is when the application and class library are not on the same computer. How do we make a call to an API on a different computer than our client?

There are several generations of solutions for this problem, such as Remote Procedure Call (RPC), Common Object Request Broker Architecture (CORBA), etc. Eventually, developers grafted remote calls onto web servers. This results in the class libraries residing on the web server and exposing the API of class libraries through the HTTP protocol.

In this way, web servers centralize the computing power and publish it as web services, while the web clients consume the computing power remotely. Since the web clients are still calling the API of the class libraries but remotely through the web, we call this kind of web service, Web API. In short, if a web service acts as the wrapper of class libraries and just exposes remote computing ability, we call it Web API.

There are many styles and rules for designing these web APIs,

  • Simple Object Access Protocol (SOAP) provides a convention for representing remote procedure calls and responses. If a web service adopts SOAP, we call this web service a SOAP Web Service or SOAP Web API.

  • Representational state transfer (REST) is a set of architectural constraints (NOT a protocol or standard), for web application design. Since a web service is a kind of web application, we can apply REST constraints to the design of web services. Once a web service adopts REST concepts, we call it a RESTful Web Service or RESTful Web API.

In much the same way that we simply call a local variable, "variable", and call a parameter variable, "parameter", we always simplify the name SOAP Web Service to Web Service, and the RESTful Web Service to Web API. This implies that most of the modern Web APIs tend to adopt the REST concept as their design principle.

文献来源

  1. edX Build Web APIs using ASP.NET Course  Module 1 | Introduction to Web API  Lesson One: What is Web API?  What is Web API?

及时获取我发的文章,学习更多编程知识欢迎关注我的个人微信公众号:

 

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:岁月 设计师:pinMode 返回首页
评论 1

打赏作者

爱吃柚子的梨

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值