The easiest way to interact with a graphql api
- Fast as fuck
- No need for openssl or other ssl libraries when compiling
Zuhyo can be installed through nimble (coming soon)
nimble install zuhyo
or through git
nimble install https://github.com/arashi-software/zuhyo
GraphQL query from a file
let
api = zuhyo.newClient("https://graphql.anilist.co") # Create a new zuhyo client; Pass in the api endpoint
query = "tests/test.gql".readQuery(vars {"id": "15125"}) # Read a file to create a query and pass in variables using the vars function
req = api.request(query) # Finally request from the api using the graphql query we just created
echo req.code # Response code of the request
echo req.headers # Headers returned in the request
echo req.body # Actual json
GraphQL query from text
let
api = zuhyo.newClient("https://graphql.anilist.co") # Create a new zuhyo client; Pass in the api endpoint
query = """
query ($id: Int) { # Define which variables will be used in the query (id)
Media (id: $id, type: ANIME) { # Insert our variables into the query arguments (id) (type: ANIME is hard-coded in the query)
id
title {
romaji
english
native
}
}
}
""".newQuery(vars {"id": "15125"}) # Read a file to create a query and pass in variables using the vars function
req = api.request(query) # Finally request from the api using the graphql query we just created
echo req.code # Response code of the request
echo req.headers # Headers returned in the request
echo req.body # Actual json