There is nothing to install and nothing to sign up for. Make a request.
curl
JavaScript
Python
PHP
curl https://hogwarts-api.com/api/spells/expecto-patronum
const res = await fetch ( 'https://hogwarts-api.com/api/spells/expecto-patronum' );
const { data } = await res. json ();
console. log (data.name, '—' , data.effect);
import requests
res = requests.get("https://hogwarts-api.com/api/spells/expecto-patronum")
data = res.json()["data"]
print(data["name"], "—", data["effect"])
<?php
$res = file_get_contents('https://hogwarts-api.com/api/spells/expecto-patronum');
$data = json_decode($res, true)['data'];
echo $data['name'] . ' — ' . $data['effect'];
A single record is addressed by its slug. The route also accepts a full name, and
anything that slugifies to a known slug — so all three of these return Hermione:
curl https://hogwarts-api.com/api/characters/hermione-granger
curl https://hogwarts-api.com/api/characters/Hermione%20Granger
curl "https://hogwarts-api.com/api/characters/Hermione Jean Granger"
If you do not know the slug, search for it first:
curl "https://hogwarts-api.com/api/characters?search=weasley"
Pulling every Gryffindor with a known patronus:
const gryffindors = [];
let page = 1 ;
let totalPages = 1 ;
do {
const res = await fetch (
`https://hogwarts-api.com/api/characters?page=${ page }&page_size=100` ,
);
const { data , meta } = await res. json ();
totalPages = meta.total_pages;
gryffindors. push (
... data. filter ( c => c.house === 'Gryffindor' && c.patronus),
);
page += 1 ;
} while (page <= totalPages);
console. log ( `${ gryffindors . length } Gryffindors with a known patronus` );
Ask for page_size=100 when paging through a whole collection. It is the maximum,
and it turns 217 requests for the character list into 55.