GraphQL is an application-layer query language that can be used with any database. It is also open source (MIT license) and was created by Facebook. It mainly differs from REST in that GraphQL does not use endpoints, but queries instead, and is supported by most server languages, such as JavaScript (Node.js), Go, Ruby, PHP, Java, and Python.
We'll now look at the main differences between GraphQL and REST.
GraphQL:
- The queries are readable
- You can evolve the API without versions
- Type system
- You can avoid doing multiple round trips to fetch related data
- It's easy to limit the set of data we need
REST:
- In REST, everything is a resource
- REST is schemaless
- You need versions to evolve the API
- It's hard to limit the set of data we need
- If you need data from different resources, you need to make multiple requests