Routing

Shipclojure uses reititarrow-up-right for both frontend and backend routing because it is the fastest router in the clojure ecosystem and it is data oriented (you can represent your routes as vectors):

(def routes ["/" {:handler (fn [req] {:status 200 :body "Hello"})}])

Fair warning: Reitit is a bit hard to grasp as first but no worries since most of the middleware and hard wiring is done for you.

Swagger

Shipclojure uses swaggerarrow-up-right for documentation, if you have your server running, visiting http://localhost:8080/api should show you the swagger documentation for all routes: api, web routes & websocket.

Routes

The routes are split into 3 categories:

  1. REST api routes: api.cljarrow-up-right

  2. Websocket routes: websocket.cljarrow-up-right

  3. Frontend routes (mix of static pages rendered on the backend and frontend only routes): common/routes.cljcarrow-up-right

How to know which frontend routes are server rendered and which are frontend only: Frontend routes will have a :view while backend routes will have the normal syntax of :get/:post (fn [req] (render-page req)).

Example

(def routes
["" #?(:clj {:get root}) ;; the default empty html that just renderes on the frontend
 ["/" (merge {:seo/title "Home"
              :seo/description "The SaaS boilerplace for your next project"
              :name ::index}
              ;; Rendered on the backend
             #?(:clj {:get layout/landing-page}))]
 ["/verify" (merge
              {:name ::verify
               :seo/title "Verify your account"
               :seo/description "Finish creating account by confirming your email"}
              ;; Rendered frontend only
              #?(:cljs {:view verify/verify-email-page}))]])

Middleware

The shipclojure router has middleware already setup for your convenience.

See all the middleware here: handler.cljarrow-up-right

Here is the documentation for reitit middlewarearrow-up-right

Websockets

Websockets use ring.websocketarrow-up-right. Read the documentation to understand how it works.

Last updated