🚀
ShipClojure
  • README
  • Development
    • Getting Started
    • REPL Workflow
    • AI Development with ShipClojure
    • Getting Updates
    • Formatting code
    • ShipClojure Guiding Principles
  • Backend
    • Migrations
    • Secrets
    • Routing
    • ShipClojure Blog
    • Email
  • Frontend
    • UIx + re-frame
    • HTTP Requests with Re-frame
    • Frontend Navigation with Re-frame
    • Toast Notifications
    • Icons
  • Server Side Rendering
    • Static/Landing pages
  • Auth
    • How Auth works
    • Oauth2 providers
  • Deployment
    • Deployment
  • Decisions
    • 001 - Cookie Sessions
    • 002 - Single Page Application Architecture
    • 003 - Re-frame instead of Refx
    • 003 - Move from cookie sessions to JWT Access + refresh tokens
Powered by GitBook
On this page
  • Swagger
  • Routes
  • Middleware
  • Websockets
  1. Backend

Routing

PreviousSecretsNextShipClojure Blog

Last updated 1 month ago

Shipclojure uses 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 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:

  2. Websocket routes:

  3. Frontend routes (mix of static pages rendered on the backend and frontend only routes):

    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.

Websockets

See all the middleware here:

Here is the

Websockets use . Read the documentation to understand how it works.

reitit
swagger
api.clj
websocket.clj
common/routes.cljc
handler.clj
documentation for reitit middleware
ring.websocket