What is GraphQL?
Getting started with AniList's GraphQL API.
GraphQL is a strongly typed API query language. It allows clients to define the structure of data required and the server will respond with data in the same structure. This helps avoid the problems of both over and under-fetching data, while also allowing for a more powerful and flexible API.
:::info Prerequisite Knowledge Before continuing, it is highly recommended that you familiarize yourself with GraphQL. The official GraphQL documentation is a good place to start. :::
Making a GraphQL API request
AniList requires all GraphQL requests be made as POST
requests to https://graphql.anilist.co
.
When making a request, you will need to include 2 objects in your payload: query
and variables
.
query
: This is your query or mutation string. It defines the data and shape of data that you would like.variables
: Contains the values for the variables used within your query.
The variables
object is optional if you are not using any, however, it is recommended that you use variables wherever it makes sense.
:::details Example Query Let's create a simple query to get an anime by it's unique ID.
::: code-group <<< @/guide/snippets/graphql/getting-started/javascript.js{js:line-numbers} [Javascript] <<< @/guide/snippets/graphql/getting-started/php.php{php:line-numbers} [PHP] <<< @/guide/snippets/graphql/getting-started/python.py{py:line-numbers} [Python] <<< @/guide/snippets/graphql/getting-started/rust.rs{rs:line-numbers} [Rust] :::
The request in the above example will return the following JSON response:
Tooling
GraphQL has been used in major projects throughout the industry for over a decade, including Airbnb, Intuit, Microsoft, and more. It is battle tested and has many powerful tools for you to use.
These are some recommended tools for working with AniList:
Apollo Studio is a powerful tool for exploring and testing your GraphQL queries. It is a great way to get started with GraphQL and AniList.
Skip service-specific API clients and generate always up-to-date typings for your language of choice.
Last updated