Accio (AK-eee-oh) API

Posted by in Technology

(Header Image by xxdulce)

I have started building!

I spent a decent portion of yesterday and today getting to grips with Python and Flask and the various features available from both. ‘Python and Flask?’ I hear you ask? Yes. Originally I decided I was going to build the PotterAPI using a MEAN stack. Having been introduced to Python and Flask, some of the features available really impressed me and got me excited so I have now decided to use these technologies instead!

Much of yesterday was spent putting together the database holding all of the available data (a SQLite Database, for now). So far, the database contains all of the Books, Films and over 200 different spells (take that, Gandalf!…LOTRAPI anyone?). The last push on the data front will be to compile all of the character data and get that into the database so that the models and api routes can be tested. I’d also like to add a couple of fields to the books, films, and characters to link up which characters appear in which films / books. This might be saved for a later release though as it will comprise a significant manual effort.

A couple of bugs yesterday caused a few delays in development. Namely a MarshalingException: Coercing to Unicode error that wasn’t very descriptive to me! However, after removing the retr function I had on my database models, this error disappeared…it only took a few hours to notice this was the problem.

So, what does a sample response currently look like? Take a look:

HTTP/1.0 200 OK
Content-Type: application/json
Content-Length: 267
Server: Werkzeug/0.10.4 Python/2.7.8
Date: Sun, 12 Apr 2015 15:21:38 GMT

{
    "spell": {
        "effect": "Tickles target and weakens", 
        "incantation": "Titillando (TITI-lan-doh)", 
        "light": "Purple", 
        "name": "Tickling Hex", 
        "spell_id": 236, 
        "type": "Hex", 
        "uri": "/spells/236"
    }
}

Or how about for a book…let’s take my favourite as an example:

HTTP/1.0 200 OK
Content-Type: application/json
Content-Length: 754
Server: Werkzeug/0.10.4 Python/2.7.8
Date: Sun, 12 Apr 2015 15:20:35 GMT

{
    "book": {
        "book_id": 3, 
        "cover_artist_name": "Mary GrandPre (US)  Kazu Kibuishi (US) Cliff Wright (UK)", 
        "followed_by": [
            {
                "book_id": 4, 
                "name": "Harry Potter and the Goblet of Fire", 
                "uri": "/books/4"
            }
        ], 
        "name": "Harry Potter and the Prisoner of Azkaban", 
        "pages": "317 (UK) 435 (US)", 
        "preceeded_by": [
            {
                "book_id": 2, 
                "name": "Harry Potter and the Chamber of Secrets", 
                "uri": "/books/2"
            }
        ], 
        "publisher": "Bloomsbury (UK) Scholastic (US)", 
        "release_date": "8 July, 1999", 
        "uri": "/books/3"
    }
}

Well that’s it for now! Still to come is the character data…and then, of course, moving everything from its single file into proper modules like a real developer!