Những vấn đề của REST API, GraphQL có phải là giải pháp giúp khắc phục?

Theo chân của tác giả Samer Buna, tác giả cũng có vài topic hay về Node JS :ok_hand:Xin trích đoạn trong bài > Rest APIs are REST-in-Peace APIs. Long Live GraphQL.
What’s wrong with REST APIs?
The biggest problem with REST APIs is the nature of multiple endpoints. These require clients to do multiple round-trips to get their data.
REST APIs are usually a collection of endpoints, where each endpoint represents a resource. So when a client needs data from multiple resources, it needs to perform multiple round-trips to a REST API to put together the data it needs.
In a REST API, there is no client request language. Clients do not have control over what data the server will return. There is no language through which they can do so. More accurately, the language available for clients is very limited.
For example, the READ REST API endpoints are either:
GET /ResouceName - to get a list of all the records from that resource, or
GET /ResourceName/ResourceID - to get the single record identified by that ID.
A client can’t, for example, specify which fields to select for a record in that resource. That information is in the REST API service itself and the REST API service will always return all of the fields regardless of which ones the client actually needs. GraphQL’s term for this problem is over-fetching of information that’s not needed. It’s a waste of network and memory resources for both the client and server.
One other big problem with REST APIs is versioning. If you need to support multiple versions, that usually means new endpoints. This leads to more problems while using and maintaining those endpoints and it might be the cause of code duplication on the server.
Bạn có thể xem thêm ví dụ trên link https://medium.freecodecamp.org/rest-apis-are-rest-in-peace-apis-long-live-graphql-d412e559d8e4
IF you’re interested, you can follow his online course or ask question on Slack.
Enjoy!!!

2 Likes

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?