In this tutorial we’ll learn how to send requests to Igloo using C++, we’ll assume that you are already familiar with the concepts of GraphQL requests and how Igloo works, if not you can check out our Getting Started series.
Sending the first request
The key ingredients of a request to Igloo are:
- the payload: it should be a JSON containing a field
querywhose value is the query or mutation to execute in Igloo
- the headers: the request should have an
Content-Typeheader specifying that the payload is a JSON and an
Authorizationheader that contains your access token
- the request verb: requests in GraphQL are always POST requests, even when you are not modifying data
Knowing this we can write a script to fetch our user’s email:
If you substitute your token in the code and run it you should get a response like
When you’ll write your own GraphQL requests be careful to escape any
" characters as
\\\", otherwise the json won’t be valid.
Parsing the response
In general the response of any Igloo request is a JSON containing a field
data if it was successful and a field
errors if something bad happened.
To avoid unexpected issues we should check if the response contains any errors before reading the data, to do that you can use the following script: