API 哪个类似于 REST,但也使用像 GraphQL 这样的突变?

API which is REST-like but also uses mutations like GraphQL?

设计一个 API 是否会存在任何巨大缺陷,使其类似于 REST,因为资源(即 /courses、/professors、/students)有 GET 端点,但所有 POST/PUT/DELETE 使用带有负载的单个端点(即 /actions),该负载指定应如何处理请求以及处理它所需的必要信息(即 { action_name = "create_course", name = "math" } 或 { action_name = "drop_course", course_id = 5 }).

Would there be any huge flaws

缓存。

缓存是 REST architectural style; "large-grain hypermedia data" wants to be cached so that you aren't repeatedly sending the same data over the network again and against. In HTTP, we've got an RFC dedicated to caching semantics 中的一个重要元素。这包括缓存失效——如果有一个成功的不安全请求,通用的 http 感知组件将知道使缓存条目失效。

因此,通过将所有不安全请求路由到单个端点,通用组件最终将缓存失效应用到操作端点,而不是应用到请求实际更改的任何资源。

DELETE 还有一个缺陷——它不需要有效负载

A payload within a DELETE request message has no defined semantics; sending a payload body on a DELETE request might cause some existing implementations to reject the request.

因此,任何参与消息交换的通用组件都将假定 /actions 端点已被删除,而不是有效负载引用的某些任意资源。

PUT 有一些不同的问题

The PUT method requests that the state of the target resource be created or replaced with the state defined by the representation enclosed in the request message payload.

因此,在您的情况下,通用组件将假设您的消息实际上是 /actions 资源的提议表示。

统一接口的要点是每个人 都同意语义,并且您可以从不了解您的特定域的通用 HTTP 感知库中提取价值。当您开始在语义上胡思乱想时,您将对可能发生的 属性 的任何损失承担责任。

远程创作语义 (PUT/PATCH/DELETE) 确实不适合单个 /actions 端点。

POST 做得更好一点,因为限制是最小的。在某种程度上,POST将所有内容都连接到一个端点可将 HTTP 从应用程序协议缩减为传输协议。

请注意,GraphQL 和之前的 SOAP 接受了这种权衡。课程用马。

What are "generic HTTP components"?

浏览器、缓存、代理、服务器、爬虫....任何可以访问正在交换的消息的东西,但不能访问您所在域的带外细节。

Also by cache invalidation of successful unsafe requests do you mean that if tracking recipes, a GET to /recipes would be cached until a GET/PUT/PATCH/DELETE request to /recipes comes along?

/recipes 的 GET 响应可能会被缓存,直到出现对 /recipes 的 POST/PUT/PATCH/DELETE。

是否缓存取决于响应提供的缓存语义headers。

当然,我的本地缓存不会知道发出的请求,所以我可能正在查看过时的副本。不过,对于我自己的更改,我会获得“阅读您自己的文章”语义。

更有趣的情况是服务器前面的反向代理,它会在成功的不安全请求后使其缓存条目无效,从而减少服务器上的负载,同时仍然提供新数据。