Rest Apis 需要使用 HTTP2 来实现异步吗?

huangapple go评论54阅读模式
英文:

Does Rest Apis need to be implemented using http2 to be asynchronous?

问题

我们目前正在升级一个API。以前,API会对成功的请求响应200状态码,并使用会话ID进行身份验证。在API的新版本中,响应是202,并且使用JWT令牌进行身份验证。

现在,如果有人声称旧的API是同步的,而新的API是异步的:

  1. 这是否意味着新的API是使用HTTP/2实现的,因为它通常与异步行为相关联?

  2. 我们的请求是否可能已经被服务器接收并推送到处理队列中,但尚未成功处理(我们也可以称之为异步),并且HTTP版本的选择是无关紧要的?如果是这样,为什么我们要特别将异步行为归因于HTTP/2,而不提到HTTP/1.1也可以表现出异步行为?我们所指的HTTP/2中的异步行为的哪个方面?

英文:

We are currently upgrading an API. Previously, the API would respond with a 200 status code for successful requests and utilize session IDs for authentication. In the new version of the API, the response is 202, and it employs JWT tokens for authentication.

Now, if someone claims that the older APIs were synchronous and the new APIs are asynchronous:

  1. Does this imply that the new APIs are implemented using HTTP/2 since it is often associated with asynchronous behavior?

  2. Is it possible that our request was received by the server and pushed into a processing queue but has not been successfully processed yet(we can call it also asynchronous), and the choice of HTTP version is irrelevant? If this is the case, why do we specifically attribute the asynchronous behavior to HTTP/2 and not mention that HTTP/1.1 can also exhibit asynchronous behavior? Which aspect of the asynchronous behavior in HTTP/2 are we referring to?

答案1

得分: 1

HTTP/2并不从根本上改变底层模型,但它优化了请求和响应的传输方式。我认为HTTP/2相对于HTTP/1唯一更具异步性的方面是,多个请求和响应可以在单个连接上复用。

HTTP/2不应该从根本上改变API的构建方式。当使用HTTP/2而不是HTTP/1.1时,API设计可能唯一的变化是执行许多HTTP请求更为经济,因此您可能可以创建更精细的终端点,而不是大型组合的终端点。

因此,如果您有关于'HTTP/2更具异步性'的猜测来源,获得真实的引用或链接以获取更多背景信息将有助于更好地理解作者的想法。

英文:

HTTP/2 does not fundamentally change the underlying model, but it optimizes how requests and responses are transmitted. I can't think of anything that makes HTTP/2 more asynchronous than HTTP/1 is, other than that multiple requests and responses can be muliplexed over a single connection.

It shouldn't fundamentally change how APIs are built. Perhaps the only change in API design when using HTTP/2 instead of HTTP/1.1 might be that it's cheaper to do many HTTP requests, so you could potentially create more fine-grained endpoint over large combined ones.

So if you have a source for the conjecture that 'HTTP/2 is more asynchronous' it would be helpful to get a real quote or link with more context to better understand what the writer was thinking.

答案2

得分: 0

你的服务器是由哪种软件构建的?异步与同步很少与HTTP 1.1与2有关。所以对于问题#1,我会说不。

同步服务器可能会在确定如何响应时挂起,而异步服务器则不会。在这方面最好是异步的。

在你使用的软件中,HTTP1.1与2可能很重要,但在NodeJS领域和我所了解的大多数Web服务器中并不重要。

英文:

What software is your Server made from? Async VS Sync rarely has anything to do with HTTP 1.1 VS 2. So for question #1 I'm going to say No.

A synchronous server would probably hang while it figures out how to response, while an Asynchronous server would not. Better to be async in that regard.

It maybe the case in the software you're using that HTTP1.1 vs 2 does matter, but it doesn't in NodeJS land and most Web Servers that I know of.

huangapple
  • 本文由 发表于 2023年6月13日 00:53:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76458769.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定