Skip to content

Instantly share code, notes, and snippets.

@ggb
Created October 9, 2016 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ggb/be5e06740ca49f2c3bd2fcb57258f6ee to your computer and use it in GitHub Desktop.
Save ggb/be5e06740ca49f2c3bd2fcb57258f6ee to your computer and use it in GitHub Desktop.
How to query the SWAPI (Star Wars API) with racket
#lang racket
(require json)
(require net/url)
(define (get url)
(call/input-url (string->url url)
(curry get-pure-port #:redirections 4)
port->string))
(define (get-things type)
(hash-ref (string->jsexpr
(get (string-append "http://swapi.co/api/" type "/")))
'results))
(define (get-names result)
(map (lambda (h) (hash-ref h 'name)) result))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment