Skip to content

Instantly share code, notes, and snippets.

@friemen
Last active August 29, 2015 14:01
Show Gist options
  • Save friemen/45c2ea90737ac42a6a80 to your computer and use it in GitHub Desktop.
Save friemen/45c2ea90737ac42a6a80 to your computer and use it in GitHub Desktop.
Starting with a minimalistic webapp.
(ns helloweb.core
(:require [org.httpkit.server :as httpkit]
[compojure.handler :as handler]
[ring.util.response :refer [redirect response]]
[ring.util.codec :refer [url-encode]]
[hiccup.page :refer [html5]]
[hiccup.form :as f]
[compojure.core :refer [defroutes GET POST]]
[compojure.route :as route]))
;; -------------------------------------------------------------------
;; your first webapp (yes, only a function)
(defn app
[request]
{:status 200
:body request})
;; -------------------------------------------------------------------
;; http server start/stop infrastructure
(defonce http-server (atom nil))
(defn stop!
"Stops the http server if started."
[]
(when-let [shutdown-fn @http-server]
(shutdown-fn)
(reset! http-server nil)
:stopped))
(defn start!
"Starts http server, which is reachable on http://localhost:8080"
[]
(stop!)
(reset! http-server (httpkit/run-server (handler/site #'app) {:port 8080}))
:started)
(defproject helloweb "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.6.0"]
[http-kit "2.1.19"]
[hiccup "1.0.5"]
[ring "1.3.1"]
[compojure "1.2.0"]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment