Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (ns myns.core
- (:require
- [io.pedestal.http :as http]
- [io.pedestal.http.route :as route]
- [io.pedestal.test :as test]
- [io.pedestal.interceptor.chain :as chain]))
- (defn response [status body & {:as headers}]
- {:status status :body body :headers headers})
- (def ok (partial response 200))
- (def created (partial response 201))
- (def accepted (partial response 202))
- (def echo
- {:name :echo
- :enter
- (fn [context]
- (clojure.pprint/pprint context)
- (let [request (:request context)
- response (ok context)]
- (chain/terminate (assoc context :response response))))})
- (def echo2
- {:name :echo2
- :enter (fn [context]
- (println "echo2")
- context)})
- (def routes
- (route/expand-routes
- #{["/foo" :post [echo echo2] :route-name :foo]}))
- (def service-map
- {::http/routes routes
- ::http/type :jetty
- ::http/port 8890})
- (defn start
- []
- (http/start (http/create-server service-map)))
- (defonce server (atom nil))
- (defn start-dev
- []
- (reset! server
- (http/start (http/create-server (assoc service-map ::http/join? false)))))
- (defn stop-dev
- []
- (http/stop @server))
- (defn restart
- []
- (stop-dev)
- (start-dev))
- (comment
- (start-dev)
- (restart)
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement