Make a GraphQL query request
curl 'https://countries.trevorblades.com/' \
-X POST \
-H 'content-type: application/json' \
--data '{
"query": "{ continents { code name } }"
}'
Make a mutation request
curl 'https://graphql-api-url' \
-X POST \
-H 'content-type: application/json' \
--data '{
"query":"mutation { createUser(name: \"John Doe\") }"
}'
Pass additional headers
If you need to pass authorization in a header, add another -H
argument:
curl 'https://countries.trevorblades.com/' \
-X POST \
-H 'Authorization: Token xxxxx' \
-H 'content-type: application/json' \
--data '{
"query": "{ continents { code name } }"
}'
Printing response headers
If you want to see response headers, add -D -
(dump headers to stdout):
curl 'https://countries.trevorblades.com/' \
-X POST \
-D - \
-H 'content-type: application/json' \
--data '{
"query": "{ continents { code name } }"
}'
Pretty printing response JSON
If you want to pretty print the output JSON, add | python -m json.tool
in the end of the curl call.
curl 'https://countries.trevorblades.com/' \
-X POST \
-H 'content-type: application/json' \
--data '{
"query": "{ continents { code name } }"
}' | python -m json.tool
Top comments (0)