BoneQuest / posts BLOG

APPLICATION PROGRAMMING INTERFACE

BONEQUEST API

EXAMPLES

PYTHON3: FETCH EPISODE TITLE

#!/usr/bin/env python3
import json
from urllib.request import urlopen

with urlopen("https://www.bonequest.com/api/v2/episode/69") as resp:
    data = json.loads(resp.read())

print(data["episodes"][0]["title"])

GO: RANDOM QUOTE

package main

import (
	"encoding/json"
	"fmt"
	"net/http"
)

func main() {
	req, _ := http.NewRequest("GET", "https://www.bonequest.com/api/v2/quote/random", nil)
	req.Header.Set("User-Agent", "queerballs/1.2.14b1")
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	var body struct {
		Episodes []struct {
			User  string `json:"user"`
			Quote string `json:"quote"`
		} `json:"episodes"`
	}
	if err := json.NewDecoder(resp.Body).Decode(&body); err != nil {
		panic(err)
	}

	ep := body.Episodes[0]
	fmt.Printf("%s: %s\n", ep.User, ep.Quote)
}