Registering multiple handlers while the server is running
Is there a way to register multiple handlers when starting the http-kit server:
(defroutes rest-main-app
(GET "/" "Welcome"))
(defroutes rest-events-app
(GET "/events" "Event API"))
(defn -main []
(run-server rest-main-app {:port 5000}))
How can I pass both routes to the run server, for example both rest-main-app and rest-events-app?
+3
source to share
1 answer
You can use compojure function routes
. You can also pass multiple handlers to defroutes
, below is an example:
(defroutes get-routes
(GET "/events" [] "Event API")
(GET "/" [] "Welcome"))
(defroutes post-routes
(POST "/events" [] "Post Event API"))
(def all-routes
(routes
get-routes
post-routes))
(defn -main []
(run-server all-routes {:port 5000}))
+6
source to share