REST api 和 REST 服务器有什么区别 [英] What is difference between REST api and REST server

查看:68
本文介绍了REST api 和 REST 服务器有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此有点困惑.我可以称我的 Java 服务器为 REST 服务器还是应该称其为 REST api?这个的正确术语是什么?什么时候可以调用 REST api,什么时候可以调用 REST server?

I am a little bit confused about this. Can I call my Java server REST server or should I call it REST api? What is the right terminology of this? When can you call something REST api and when REST server?

谢谢

推荐答案

简单来说,REST API 是一组 URL响应通过 HTTP 发出的请求,通常使用 GET POST PUT DELETE HTTP 方法.许多 REST API 在响应中返回 JSON.

In simple terms a REST API is a set of URLs that respond to requests made over HTTP, usually using GET POST PUT DELETE HTTP methods. Lots of REST APIs return JSON in the response.

例如,要获取客户的详细信息,REST API 可能是一个 GET 请求:

For example, to get a customer's details a REST API might be a GET request to:

https://customers.com/api/1234

响应:

{
  "id": 1234,
  "name": "Joe Bloggs"
}

REST API 部分是 /api/1234.可用于简化 REST API 创建的框架示例是 spring-boot.

The REST API part is /api/1234. An example of a framework that can be used to simplify creation of a REST API is spring-boot.

REST 服务器部分是 https://customers.com

The REST Server part is https://customers.com

REST Server 提供基础设施以允许客户端向 REST 发送 GET 请求API 并接收响应.

i.e. The REST Server is there to provide the infrastructure to allow clients to send GET requests to the REST API and receive the response.

可用作 REST 服务器的服务器示例有 Apache HTTPDTomcatIIS> 等等

Examples of servers that can be used as REST Servers are Apache HTTPD, Tomcat, IIS etc.

回答一些问题:

我应该使用 REST API 而不是服务器

I should use REST API instead of server

REST API 不能在没有 Rest Server 的情况下使用.服务器是接受对 API 的请求并促进来自 API 的响应的应用程序.REST API 客户端将向 REST Server 发送 GET 请求代码>customer.com/api/1234.REST Server 将计算出customer.com/api/1234"是在 REST Server<中运行的 Web 应用程序/code> 并将控制权传递给该 Web 应用程序.

A REST API cannot be used without a Rest Server. The server is the application that accepts requests to the API and facilitates responses from the API. The REST API client will send a GET request to the REST Server for customer.com/api/1234. The REST Server will work out that 'customer.com/api/1234' is a web application running inside the REST Server and will pass control to that web application.

下一个问题的答案来自于那次交接:

The answer to the next question follows on from that hand-over:

REST API 分为三层——表示层、业务层和数据层

REST API is divided into three tiers - presentation, business and data

这完全取决于 REST API 的开发人员.这就是 REST API 的实现细节.例如,一个典型的流程可能是:

That is entirely up to the developer of the REST API. That is the implementation detail of the REST API. For example, a typical flow might be:

  1. REST Server 接收对 customer.com/api/1234
  2. GET 请求
  3. REST Server 将控制权交给 REST API,后者接收 URL 路径参数 1234
  4. REST API 确定请求是针对客户(业务层)
  5. REST API 联系数据库以加载 id 为 1234(数据层)的客户数据
  6. REST API 返回 JSON 如上所示(表示层)
  7. REST Server 向客户端发送 JSON 响应
  1. REST Server receives GET request for customer.com/api/1234
  2. REST Server hands control to REST API which receives the URL path parameter 1234
  3. REST API determines request is for a customer (business tier)
  4. REST API contacts database to load data of the customer with id 1234 (data tier)
  5. REST API returns JSON as shown above (presentation tier)
  6. REST Server sends JSON response to the client

因此所有域操作都由 REST API(寻找客户,将数据转换为 JSON)处理,所有 Internet 操作都由 REST 处理 Server(客户端连接,HTTP 请求和响应).

So all domain operations are handled by the REST API (finding a customer, converting the data to JSON) and all internet operations are handled by the REST Server (client connections, HTTP requests and responses).

在 spring-boot 框架中,您可以使用 Java 开发您的 REST API 并且还可以将其与内置的 REST Server (Tomcat),因此您只需生成一个放在计算机上并运行的 JAR 文件.

In the spring-boot framework, you can develop your REST API using Java and also bundle it with a built-in REST Server (Tomcat) so you only produce a single JAR file that you place on a computer and run.

因此,实际上,您具有三个组件.计算机(例如连接到 Internet 的 unix 服务器,甚至是您的 pc 并使用 http://localhost/customer/api/1234).一个 REST Server(Tomcat,可以接受 HTTP 请求)和一个 REST API>(您为实现层而编写的代码).

So in effect, you have three components. The computer (for example a unix server connected to the internet, or even your pc and use http://localhost/customer/api/1234). A REST Server (Tomcat, that can accept HTTP requests) and a REST API (the code you wrote to implement the tiers).

这篇关于REST api 和 REST 服务器有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆