Kurt Vonnegut API


"If this isn't nice, what is?"


An API for Kurt Vonnegut's bibliography.
So it goes.


What is an API?

The Kurt Vonnegut API is a RESTful API built using Node.js, Express, MongoDB, and EJS. It was designed to serve metadata on Kurt Vonnegut's bibliography, currently returning information on his novels, collected works, and plays as JSON.

A RESTful API is simply computer code that uses HTTP to request services from a program running on another computer, often called a server. It allows anyone to access a partcular set of data using whatever computer language on whatever operating system. In this case, this API makes it really easy to get info on Kurt Vonnegut's bibliography. All you need is a Uniform Resource Identifier (URI) to get the data.

https://kurtvonnegutapi.com/api


Routes

Endpoint Response
/api Kurt Vonnegut's entire bibliography for novels, collected works, and plays
/api/novels List of Vonnegut's novels
/api/collections List of Vonnegut's collected works
/api/plays List of Vonnegut's plays

Metadata

Form Metadata
Novel title
subtitle
form
genre
publisher
year
pages
chapters
setting
characters
wiki
Form Metadata
Collected Work
title
form
genre
publisher
year
pages
contents
wiki


Form Metadata
Play
title
form
genre
publisher
year
setting
characters
wiki


Filters

You can currently only filter searches using the main /api route, using any combination of title, form, genre, and year seperated by an ampersand (&).

✅ https://kurtvonnegutapi.com/api?title=Slaughterhouse-Five&year=1952

You can search using multiple filters separated by commas

✅ https://kurtvonnegutapi.com/api?year=1952,1969

You cannot, however, use multiple filters and different filters at the same time.

❌ https://kurtvonnegutapi.com/api?year1952,1969&title=Breakfast of Champions


Example

GET

https://kurtvonnegutapi.com/api?title=Slaughterhouse-Five

[
    {
        _id": "5f07523011807ba43fb805b0",
        "title": "Slaughterhouse-Five",
        "subtitle": "The Children's Crusade: A Duty-Dance with Death",
        "form": "novel",
        "genre": [
            "dark comedy",
            "satire",
            "science fiction",
            "war novel",
            "metafiction",
            "postmodernism"
        ],
        "publisher": "Delacorte",
        "year": 1969,
        "pages": 215,
        "chapters": 10,
        "setting": [
            {
                "city": "Dresden",
                "country": "Germany",
                "fictional": false
            },
            {
                "planet": "Tralfamadore",
                "fictional": true
            },
            {
                "city": "Ilium",
                "state": "New York",
                "country": "United States of America",
                "fictional": false
            },
            {
                "city": "Ardennes",
                "country": "Belgium",
                "fictional": false
            }
        ],
        "characters": [
            {
                "firstName": "Billy",
                "lastName": "Pilgrim"
            },
            {
                "firstName": "Kilgore",
                "lastName": "Trout"
            },
            {
                "firstName": "Eliot",
                "lastName": "Rosewater"
            },
            {
                "firstName": "Roland",
                "lastName": "Weary"
            },
            {
                "firstName": "Paul",
                "lastName": "Lazzaro"
            },
            {
                "firstName": "Edgar",
                "lastName": "Derby"
            },
            {
                "firstName": "Robert",
                "lastName": "Pilgrim"
            },
            {
                "firstName": "Valencia",
                "lastName": "Merble"
            },
            {
                "firstName": "Barbara",
                "lastName": "Pilgrim"
            },
            {
                "firstName": "Howard",
                "middleName": "W",
                "lastName": "Campbell",
                "suffix": "Jr"
            },
            {
                "firstName": "Montana",
                "lastName": "Wildhack"
            },
            {
                "firstName": "Bertam",
                "middleName": "Copeland",
                "lastName": "Rumfoord"
            },
            {
                "firstName": "Wild Bob"
            }
        ],
        "wiki": "https://en.wikipedia.org/wiki/Slaughterhouse-Five"
    }
]

Usage

You can use any http library to return a JSON array of the data.

JavaScript

Below is an example using Request, a Node.js package.

// Request
const request = require('request');
            
request({
    url: 'https://kurtvonnegutapi.com/api?title=Slaughterhouse-Five',
    json: true
}, function (error, response, bibliography) {
    console.log(bibliography)
});

// Output
[
    {
    _id: '5f07523011807ba43fb805b0',
    title: 'Slaughterhouse-Five',
    subtitle: "the Children's Crusade: A Duty-Dance with Death",
    form: 'novel',
    genre: [
        'dark comedy',
        'satire',
        'science fiction',
        'war novel',
        'metafiction',
        'postmodernism'
    ],
    publisher: 'Delacorte',
    year: 1969,
    pages: 215,
    chapters: 10,
    setting: [ [Object], [Object], [Object], [Object] ],
    characters: [
        [Object], [Object],
        [Object], [Object],
        [Object], [Object],
        [Object], [Object],
        [Object], [Object],
        [Object], [Object],
        [Object]
    ],
    wiki: 'https://en.wikipedia.org/wiki/Slaughterhouse-Five'
    }
]

// Notice that arrays containing objects are returned as [Object]
// Use object and array notation to access
bibliography[0].characters[0]; 
/* 
{ 
    firstName: 'Billy', 
    lastName: 'Pilgrim' 
}
*/

bibilography[0].setting[0];
/*
{
    city: 'Dresden',
    country: 'Germany',
    fictional: false
}
*/

Some of the metadata may be useful for textual analysis. In particular, bibliography[i].characters and bibliography[i].setting

// Appearances of Kilgore Trout across various novels
request({
    url: 'https://kurtvonnegutapi.com/api/novels',
    json: true
}, function (error, response, bibliography) {
    let kilgoreTroutAppearances = [];
    for (let i = 0; i < bibliography.length; i++) {
        for (let j = 0; j < bibliography[i].characters.length; j++) {
            if (bibliography[i].characters[j].firstName === "Kilgore" && bibliography[i].characters[j].lastName === "Trout") {
                kilgoreTroutAppearances.push(bibliography[i])
            }
        }
    }
    console.log(kilgoreTroutAppearances)
});
/*
[
    {
    _id: '5f07523011807ba43fb805ab',
    title: 'God Bless You, Mr. Rosewater',
    subtitle: 'Pearls Before Swine',
    form: 'novel',
    genre: [ 'satire', 'postmodernism' ],
    publisher: 'Holt, Rinehart and Winston',
    year: 1965,
    pages: 218,
    chapters: null,
    setting: [ [Object], [Object] ],
    characters: [ [Object], [Object], [Object] ],
    wiki: 'https://en.wikipedia.org/wiki/God_Bless_You,_Mr._Rosewater'
    },
    {
    ...
    }
]
*/

Python

Requests, an HTTP library for Python, gives you a simple method for returning data

# returns JSON array
import requests

response = requests.get('https://kurtvonnegutapi.com/api?title=Slaughterhouse-Five')

print(response.json())

# output
"""
[{'_id': '5f07523011807ba43fb805b0', 'title': 
'Slaughterhouse-Five', 'subtitle': "the Children's
Crusade: A Duty-Dance with Death", 'form': 'novel',
'genre': ['dark comedy', 'satire', 'science fiction', 
'war novel', 'metafiction', 'postmodernism'], 
'publisher': 'Delacorte', 'year': 1969, 'pages': 215, 
'chapters': 10, 'setting': [{'city': 'Dresden', 
'country': 'Germany', 'fictional': False}, {'planet': 
'Tralfamadore', 'fictional': True}, {'city': 'Ilium', 
'state': 'New York', 'country': 'United States of 
America', 'fictional': False}, {'city': 'Ardennes', 
'country': 'Belgium', 'fictional': False}], 
'characters': [{'firstName': 'Billy', 'lastName': 
'Pilgrim'}, {'firstName': 'Kilgore', 'lastName': 
'Trout'}, {'firstName': 'Eliot', 'lastName': 
'Rosewater'}, {'firstName': 'Roland', 'lastName': 
'Weary'}, {'firstName': 'Paul', 'lastName': 'Lazzaro'}
, {'firstName': 'Edgar', 'lastName': 'Derby'}, 
{'firstName': 'Robert', 'lastName': 'Pilgrim'}, 
{'firstName': 'Valencia', 'lastName': 'Merble'}, 
{'firstName': 'Barbara', 'lastName': 'Pilgrim'}, 
{'firstName': 'Howard', 'middleName': 'W', 'lastName': 
'Campbell', 'suffix': 'Jr'}, {'firstName': 'Montana', 
'lastName': 'Wildhack'}, {'firstName': 'Bertam', 
'middleName': 'Copeland', 'lastName': 'Rumfoord'}, 
{'firstName': 'Wild Bob'}], 'wiki': 'https://en.
wikipedia.org/wiki/Slaughterhouse-Five'}]
"""