REST API
Our RESTful API provides a straightforward way to interact with the Potter DB, adhering to the JSON:API and OAS specification. In this section, we'll cover the key aspects of using the REST API, including the available endpoints and how to format your requests and responses.
Available Endpoints
To access data from the REST API you need to make a GET
request to one of the followings endpoints:
Expand to see all endpoints
Books
/v1/books
: Retrieve a list of books./v1/books/{id}
: Retrieve a single book by its ID./v1/books/{book_id}/chapters
: Retrieve a list of chapters for a given book./v1/books/{book_id}/chapters/{id}
: Retrieve a single chapter for a given book by its ID.
Characters
/v1/characters
: Retrieve a list of characters./v1/characters/{id}
: Retrieve a single character by its ID.
Movies
/v1/movies
: Retrieve a list of movies./v1/movies/{id}
: Retrieve a single movie by its ID.
Potions
/v1/potions
: Retrieve a list of potions./v1/potions/{id}
: Retrieve a single potion by its ID.
Spells
/v1/spells
: Retrieve a list of spells./v1/spells/{id}
: Retrieve a single spell by its ID.
IDs must be provided as UUIDs or slugs.
OpenAPI Specification (OAS)
To make integration easier, we provide an OpenAPI Specification (opens in a new tab) document that describes the API's endpoints, data models and request/response schemas. The API conforms to version 3.0.3 of the OAS specification. You can find our current OAS document here (opens in a new tab).
JSON:API Format
Our REST API adheres to the JSON:API specification (opens in a new tab), which provides a consistent way to structure API requests and responses. Here's an overview of the key features of JSON:API in the context of our API:
- Resource Objects: Each resource is represented as an object with a
type
,id
andattributes
. - Relationships: Resources can be related to other resources, for example a
book
resource is related tochapter
resources and vice versa. - Pagination: When a response contains a large number of resources, the response will be paginated. See Pagination for more information.
- Errors: Errors are returned with standardized structures, making it easy to handle and troubleshoot issues.
Making Requests
To make a request to the REST API, you need to make a GET
request to one of our available endpoints.
Here's a basic example of how to retrieve a list of characters using the /characters
endpoint:
GET https://api.potterdb.com/v1/characters
Please refer to the OpenAPI Specification document for detailed information.
Pagination
Responses with a large number of resources will be paginated. The response will include a links
object with first
, last
, prev
and next
links to the first, last, previous and next pages of results respectively.
To change amount of resources per page, you can use the page[size]
query parameter (maximum size is 100):
GET https://api.potterdb.com/v1/characters?page[size]=25
To change the current page, you can use the page[number]
query parameter:
GET https://api.potterdb.com/v1/characters?page[number]=2
Ransack
Our REST API supports advanced filtering and sorting using Ransack (opens in a new tab).
Filtering
You can filter resources by adding a filter
query parameter to your request. For example, to filter characters by name, you can use the name_cont
predicate:
GET https://api.potterdb.com/v1/characters?filter[name_cont]=Weasley
This will return all characters with the name "Weasley".
Expand to see all available filter predicates
eq
: equalseq_any
: equals anyeq_all
: equals allnot_eq
: not equal tonot_eq_any
: not equal to anynot_eq_all
: not equal to allmatches
: matchesmatches_any
: matches anymatches_all
: matches alldoes_not_match
: doesn't matchdoes_not_match_any
: doesn't match anydoes_not_match_all
: doesn't match alllt
: less thanlt_any
: less than anylt_all
: less than alllteq
: less than or equal tolteq_any
: less than or equal to anylteq_all
: less than or equal to allgt
: greater thangt_any
: greater than anygt_all
: greater than allgteq
: greater than or equal togteq_any
: greater than or equal to anygteq_all
: greater than or equal to allin
: inin_any
: in anyin_all
: in allnot_in
: not innot_in_any
: not in anynot_in_all
: not in allcont
: containscont_any
: contains anycont_all
: contains allnot_cont
: doesn't containnot_cont_any
: doesn't contain anynot_cont_all
: doesn't contain allstart
: starts withstart_any
: starts with anystart_all
: starts with allnot_start
: doesn't start withnot_start_any
: doesn't start with anynot_start_all
: doesn't start with allend
: ends withend_any
: ends with anyend_all
: ends with allnot_end
: doesn't end withnot_end_any
: doesn't end with anynot_end_all
: doesn't end with all'true'
: is true'false'
: is falsepresent
: is presentblank
: is blank'null'
: is nullnot_null
: is not null
Sorting
You can sort resources by adding a sort
query parameter to your request. For example, to sort characters by name, you can use the name
attribute (go to Resources to see all available attributes):
GET https://api.potterdb.com/v1/characters?sort=name
Use the -
prefix to sort in descending order.