/plushcap/analysis/hasura/how-to-request-a-graphql-api-with-fetch-or-axios

How to request a GraphQL API with Fetch or Axios

What's this blog post about?

This article provides a comprehensive guide on how to request a GraphQL API using Fetch or Axios. It begins by explaining that GraphQL is just a query language and popular implementations leverage existing JSON standards for requests and responses over HTTP. The key components of a GraphQL request are the endpoint, headers, and request body in JSON format. The JSON body contains three objects: operationName (optional), query (the actual GraphQL query), and variables (an optional object used to pass dynamic values). The article then provides an example of a basic GraphQL query and demonstrates how to make a GraphQL API request using Fetch or Axios in JavaScript. It also explains how to handle errors in the response object. The author recommends checking out their open source tutorial on Introduction to GraphQL for those new to the technology.

Company
Hasura

Date published
Nov. 2, 2021

Author(s)
Praveen Durairaju

Word count
662

Language
English

Hacker News points
None found.


By Matt Makai. 2021-2024.