Planck HTTP

May 15, 2016

Once exciting new feature in Planck 1.12 is support for HTTP.

Planck has long had support for interacting with the local file system via planck.io and also interacting with local programs via planck.shell. But now there is a new namespace, planck.http, thanks to a generous contribution by Erik Assum.




Here is an example of it in action:

cljs.user=> (require '[planck.http :refer [get]])
nil
cljs.user=> (-> (get "http://planck-repl.org")
       #_=>  (select-keys [:status :headers]))
{:status 200,
 :headers {:Server "nginx/1.4.6 (Ubuntu)",
           :Transfer-Encoding "Identity",
           :Cache-Control "max-age=172800",
           :Date "Sat, 14 May 2016 20:33:33 GMT",
           :Content-Encoding "gzip",
           :Connection "keep-alive",
           :Content-Type "text/html",
           :Last-Modified "Mon, 25 Apr 2016 13:38:49 GMT",
           :Expires "Mon, 16 May 2016 20:33:33 GMT"}}

You can also use the library to do post requests.

And (this is pretty cool, IMHO), since things are hooked in using the IOFactory pattern, you can use slurp:

(slurp "http://planck-repl.org")
"<html ...

There are plenty of options that you can pass to this new API to control timeouts and other aspects. Give it a try!

You can get Planck 1.12 at http://planck-repl.org.

Tags: ClojureScript Bootstrap