- Products
- Solutions Use casesBy industry
- Developers
- Resources ConnectAbout Nylas
- Pricing
$ curl -X GET 'https://my.api.com/person/my_friend'
{ "name": "My Friend", "birthday": "1971-01-01", "favorite_food": "Pizza!", "id": "my_friend", "hair_color": "Black", "eye_color": "Blue", "car": "1981 DeLorean" }
This response includes all the information we need, but it also includes things we don’t care about for this use case, like the color of our friend’s hair and the car they drive. GraphQL is better in this situation because it allows you to request only the data objects you care about. So, the request would look like this:
$ curl -X GET 'https://my.api.com' --data ' { person(id: "my_friend") { birthday favorite_food } }'
{ "data": { "person": { "birthday": "1971-01-01", "favorite_food": "Pizza!" } } }
$ curl -X GET 'https://my.api.com/person/my_friend' { "name": "My Friend", "birthday": "1971-01-01", "favorite_food": "pizza" } $ curl -X GET "https://my.api.com/food/pizza" { "name": "pizza", "stores": ["Pizza Express", "Gormet Pizza Delivery", "AAA Pizza"] }
$ curl -X GET 'https://my.api.com' --data ' { person(id: "my_friend") { birthday favorite_food{ name stores } } }' { "data": { "person": { "birthday": "1971-01-01", "favorite_food": [ "name": "pizza", "stores": ["Pizza Express", "Gormet Pizza Delivery", "AAA Pizza"] ] } } }
We could take this further to request additional information for the store objects such as the website URL and physical address if we also wanted to use that data. Keep in mind that each of these objects probably have data fields we don’t need for our use case. With REST, each of these objects will return all data, which can quickly add up in situations that have unreliable internet connections or bandwidth.
Quite a few companies are making the jump to GraphQL, this is evidenced by all of the companies that have joined the GraphQL Foundation. GitHub is one notable company who released v4 of their API with GraphQL; they give the following reasoning:
“GitHub chose GraphQL for our API v4 because it offers significantly more flexibility for our integrators. The ability to define precisely the data you want—and only the data you want—is a powerful advantage over the REST API v3 endpoints. GraphQL lets you replace multiple REST requests with a single call to fetch the data you specify.”
Shopify released a GraphQL API in 2018 to make it easier to build and manage online storefronts, they like it because it helps reduce requests that are made to their API servers:
“GraphQL gave us big wins by reducing the number of round trips made to the server and giving us a well defined and strongly typed schema to work against. GraphQL has also played a major role in helping us find and fix bugs before impacting our merchant’s daily operations.”
Yelp released their first GraphQL API in 2017 and like it for how easy it is to access relational data:
“GraphQL also makes traversing graphs (and therefore relational data) very easy. Unlike most REST APIs, you don’t need to make multiple requests to pull relational data. Based on the schema, you can retrieve data based on the relations they have. For our API users, this means easy access to all the great business information we have available.”
Learn how to integrate advanced scheduling features into your application using Nylas Scheduler v3 to streamline appointment booking and enhance user productivity.
This blog post covers how to setup Nylas API v3 webhooks using Hookdeck to receive real-time calendar, and email updates in your application.
Create and read your Google webhooks using Ruby and Sinatra, and publish them using Koyeb. Here’s the full guide.
Ben is the Developer Advocate for Nylas. He is a triathlete, musician, avid gamer, and loves to seek out the best breakfast tacos in Austin, Texas.