Created
October 9, 2016 21:03
-
-
Save ggb/be5e06740ca49f2c3bd2fcb57258f6ee to your computer and use it in GitHub Desktop.
How to query the SWAPI (Star Wars API) with racket
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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