Skip to content

Instantly share code, notes, and snippets.

@RobertARandolph
Created May 22, 2019 17:47
Show Gist options
  • Select an option

  • Save RobertARandolph/60f0b316c8e3bd8f6288f092fc2a0d66 to your computer and use it in GitHub Desktop.

Select an option

Save RobertARandolph/60f0b316c8e3bd8f6288f092fc2a0d66 to your computer and use it in GitHub Desktop.
(ns http-direct.tutorial
(:require
[clojure.java.io :as io]
[clojure.edn :as edn]))
(defn read-edn
[input-stream]
(some-> input-stream io/reader (java.io.PushbackReader.) edn/read))
(defn handler
"Returns a cheerful message in response to a :ping in the body"
[{:keys [headers body]}]
(let [type (some-> body read-edn)]
(if (= type :ping)
{:status 200
:headers {"Content-Type" "text/plain"}
:body "Hey! It's working!"}
{:status 400
:headers {}
:body "Expected a :ping"})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment