July 6, 2022

application/json vs application/graphql

You might have seen that now we have a GraphQL API called Fusion Data API.

When sending requests to its endpoint you can choose to send the content as either application/graphql:

curl --request POST \
  --url https://developer.api.autodesk.com/fusiondata/2022-04/graphql \
  --header 'Authorization: Bearer iieT1Jj456BNhK9EfsHfSx1G0YW1' \
  --header 'Content-Type: application/graphql' \
  --data '{hubs(filter:{name:"MyHub"}){results{id}}}'

or application/json (notice how the query inside the --data is now wrapped in a json format):

curl --request POST \
  --url https://developer.api.autodesk.com/fusiondata/2022-04/graphql \
  --header 'Authorization: Bearer iieT1Jj456BNhK9EfsHfSx1G0YW1' \
  --header 'Content-Type: application/json' \
  --data '{"query":"query{hubs(filter:{name:\"MyHub\"}){results{id}}}"}'

If you're using tools like Postman or Insomnia and set the content type to GraphQL then your query will be turned into json format in the background and sent as application/json (the Content-Type header value will be set to that automatically so no need for you to add anything)

If you're not sure how exactly the tool or library you are using is sending the request then you can easily double-check that using a website like https://webhook.site/ which generates a URL for you where you can send your request - see image at the top of the article.

Related Posts