Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (ns myns.core
  2.   (:require
  3.     [io.pedestal.http :as http]
  4.     [io.pedestal.http.route :as route]
  5.     [io.pedestal.test :as test]
  6.     [io.pedestal.interceptor.chain :as chain]))
  7.  
  8. (defn response [status body & {:as headers}]
  9.   {:status status :body body :headers headers})
  10.  
  11. (def ok (partial response 200))
  12. (def created (partial response 201))
  13. (def accepted (partial response 202))
  14.  
  15. (def echo
  16.   {:name :echo
  17.    :enter
  18.          (fn [context]
  19.            (clojure.pprint/pprint context)
  20.            (let [request (:request context)
  21.                  response (ok context)]
  22.              (chain/terminate (assoc context :response response))))})
  23.  
  24. (def echo2
  25.   {:name  :echo2
  26.    :enter (fn [context]
  27.             (println "echo2")
  28.             context)})
  29.  
  30. (def routes
  31.   (route/expand-routes
  32.     #{["/foo" :post [echo echo2] :route-name :foo]}))
  33.  
  34. (def service-map
  35.   {::http/routes routes
  36.    ::http/type   :jetty
  37.    ::http/port   8890})
  38.  
  39. (defn start
  40.   []
  41.   (http/start (http/create-server service-map)))
  42.  
  43. (defonce server (atom nil))
  44.  
  45. (defn start-dev
  46.   []
  47.   (reset! server
  48.           (http/start (http/create-server (assoc service-map ::http/join? false)))))
  49.  
  50. (defn stop-dev
  51.   []
  52.   (http/stop @server))
  53.  
  54. (defn restart
  55.   []
  56.   (stop-dev)
  57.   (start-dev))
  58.  
  59. (comment
  60.   (start-dev)
  61.   (restart)
  62.   )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement