AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Graphql vs rest1/7/2023 GraphQL’s strengths of GraphQL also have weaknesses. So we have seen 4 major advantages GraphQL has over the RESTfull style:īut not everything is rosy. GraphQL’s strong typing, therefore, works particularly well with TypeScript and typed languages in general (like Flutter). We can see that we can retrieve object types directly from the GraphQL API. For example, in the StarWars API just installed above, we can do: query In the read query, we list all the fields we want to have in return. All you need to do is a git clone a yarn install and yarn dev! Now, I’m a big fan of learning by doing, and we’ll be using the Star Wars GraphQL API, you can follow along if you like. You can send a read request, known as “Query”, or a write request, known as a “Mutation”. We send an HTTP request that contains a page of text written in GraphQL that describes our query. In GraphQL you only talk to one entry point. In REST the entry point (the URL called and the HTTP verb used) determines the server’s response is determined. Unlike REST, GraphQL truly is a query language, as is for example the Structured Query Language (also known as SQL). Unlike REST where one request will usually only get you one “type” of item.Īnd therein lies the meaning of the name GraphQL, which stands for “ Graph Query Language”. GraphQL provides the means to create queries that traverse this graph, across different kinds of objects. These links, combined together, form a graph, where nodes (users, pages) are linked together (via likes, follows, views & visits…). Who are my friends’ friends? What content do they like? What do they watch? What type of content do they respond to?Ĭonceptually friendships, follows, and likes are links. We request that the server provide us with the data of a given book, or a collection of books, for example.īut social networks are about relationships between different types of items. In REST terms, these are respectively called “resources” and “resource collections”. To simplify, the purpose of REST is to communicate an item or several items of a collection or table in a database. After all, REST stands for Representational State Transfer. What do I mean by that? Well, REST is particularly suited to the classic table-based database setup, where each row represents an object. A problem that the “like button” itself embodies.īecause GraphQL’s main purpose is to navigate a relational network. And it was built to meet a need specific to social networks. To understand GraphQL, and the purpose it serves, we will be comparing it with how REST APIs are organized.Īnd truth be told, you could almost say that GraphQL exists because of “likes”. I’ve already written about APIs in general, and REST web APIs in particular.Īnd while the REST standard is the standard way to organize an API, GraphQL is steadily challenging that position of dominance. What is the need they exist to serve? What are they used for? Why and how to use them? So many questions!Īnd we’ll see the four advantages that GraphQL has over the REST-ful style of APIs.Īnd then the 2 major disadvantages that you have to watch out for if you use or create an API in GraphQL.īut before that, let’s start at the beginning: What is GraphQL? Let’s take a look at what GraphQL is, what REST is, and when you should choose one over the other. It’s time to explore together the wonderful world of GraphQL and REST! A neural network “imagined” by MidJourney
0 Comments
Read More
Leave a Reply. |