top of page

Short practical guide to interacting with API’s and GraphQL

Updated: Aug 2, 2022

GraphQL is an alternative to RESTful API design to improve client-server communication. 👨‍💻

In this post, you will learn how to use GraphQL 💻


Today we have so many platforms to deliver our services such as the web, phones, tablets, desktop applications, IoT and each one has its own way of doing things.


Thanks to that a greater number of services are created for each application depending on the need, so how to handle this complexity efficiently?


GraphQL replaces REST "best practices" with a clear and simple structure



In this post, we will teach you about GraphQL, which is quite simple and works without specialized tools. So, you will learn how to call a GraphQL API over HTTP.




GRAPH QL

TALK OF THE WEEK


How works?

GraphQL servers are easy to build compared to a traditional RESTful API. All you need to do is create a schema or directory of defined data types in your application, then fields within the types, and a function for each field that tells the server where and how to get the data.


For example, a GraphQL service that tells you who the logged-in user is as well as the name of that user might look like this:


type Query {
  me: Hero
}
type Hero {
  id: ID
  name: String
  . . .
}

Along with functions for each field on each type:


function QueryMe(request) {
  return request.auth.hero;
}
function HeroName(hero) {
  return hero.getName();
}

After a GraphQL service is running (typically at a URL on a web service), it can receive GraphQL queries to validate and execute.



The service first checks a query to ensure it only refers to the types and fields defined and then runs the provided functions to produce a result.

​​



GraphQL queries access not just the properties of one resource but also smoothly follow references between them.




While typical REST APIs require loading from multiple URLs, GraphQL APIs get all the data your app needs in a single request.






Apps using GraphQL can be quick even on slow mobile network connections.

Get many resources in a single request




Public GraphQL APIs

A collective list of public GraphQL APIs for your projects and demos. In the GitHub Repository list, the PRs are welcome 😄



If you are interested in GraphQL in general, check out awesome-graphql.


_________________________________________________________________________________________


¡Thanks for reading!


📍 Connect with us on instagram👇


39 views

Join our newsletter to receive information about latest technologies trends and job offers

Thanks for subscribing!

bottom of page