问题描述
有人尝试开发 GraphQL 而不是 RESTful API吗?有人可以给出现实生活中(不仅是理论上的)利与弊的信息.基本上从我的研究中,我发现 GraphQL 的功能是完全获得您所需要的东西.使用 REST API的地方,您通常不得不发出一系列请求,并且可以轻松地获得比实际需要更多的信息.
Did someone try developing a GraphQL instead of RESTful API? Can someone give real life (not only theoretical) pros and cons. Basically from my research I found that the GraphQL power is to get exactly what you need nothing more. Where with REST APIs, you often have to make a series of requests and you can easily get back more information than you really needed.
值得花时间研究和学习 GraphQL 吗?有任何引起您注意的bug或热门话题吗?
Is it worth the time spent on researching and learning GraphQL? Any bugs or showstoppers that get your attention?
推荐答案
此问题主要基于观点.
但是根据我的经验:对RESTful-API的仅一件事的多次请求通常表明API设计不足,即所需的资源不可用,因此需要从不同的资源中收集东西以弥补这一点.
But from my experience:Multiple requests on a RESTful-API for just one thing often indicates a lack in the API design, namely the needed resource was not available and therefore stuff needs to be gathered from different resources to compensate for this.
可以轻松地用GraphQL替换的REST-API表示该API实际上是CRUD-HTTP-API,在REST传教士中被视为反模式.
A REST-API that could be easily replaced by GraphQL indicates, that the API was in fact a CRUD-HTTP-API, what is considered an Anti-Pattern among REST-Evangelists.
另外值得注意的是,GraphQL将责任放在客户端上,因为后备API减少为只需要查询的数据存储.另一方面,REST增强了客户端的行为,因此减少了对其的责任.客户端被简化为类似于浏览器的东西.
Also worth noting is, that GraphQL puts responsibilty on the client, because the backing API is reduced to be a datastore that just needs to be queried. REST on the other hand enforces the behaviour of the client and therefore reduces responsibility on it. The client gets reduced to be something similar to a browser.
在某些情况下,一种或另一种方法会产生更好的结果,但这在很大程度上取决于您的情况.
There are cases the one or the other approach would yield better results, but that greatly depends on your situation.
这篇关于GraphQL或REST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!