

The design discussion around namespaces in the Clojure Confluence Now, I won’t spend time moaning about the current state of namespaces (see I find myself apologizing that it’s a bit complex and confusing. Create some db access functionsĬreate a src/my_webapp/db.Whenever I’m showing a newcomer to Clojure how to bring in code from other namespaces, Them all into their own db.clj file (described next). Rather than clog up this file with database-related calls, we've put In handler.clj's defroutes,Ĭompojure is helpfully taking care of placing that into a response (the ones being called in handler.clj) is returning just a plain Here we've implemented each function used in handler.clj.Īgain, note that each of the functions with names ending in "-page" ( GET "/" ( views/home-page )) ( GET "/add-location" ( views/add-location-page )) ( POST "/add-location" ( db/get-xy loc-id )] ( page/html5 ( gen-page-head ( str "Location " loc-id )) header-links ))) ( defn all-locations-page ( let ( page/html5 ( gen-page-head "All Locations in the db" ) header-links ] ( for ])]))) ])) ( defroutes app-routes replace the generated app-routes with this ( ns my-webapp.handler ( :require add this require It converts regular Clojure data structures right into To take care of this for us such that we can associate url paths withĬorresponding functions, all in one place.Ĭlojars) provides a quick and easy way to Take that incoming request map and then delegate to various functions If we were using only Ring, we'd have to write one single function to sets things up such that an http request comes into your webappĪs a regular Clojure hashmap, and likewise makes it so that youĭescribing exactly what those request and response maps shouldįor this tutorial, we won't actually need to deal with these maps.We'll use four major components (briefly described below) for our This guide uses Clojure 1.5, as well as current versions of theĬomponent libraries noted below. This work is licensed under a Creative CommonsĪttribution 3.0 Unported License (including images & It's assumed that you're already somewhat familiar with Clojure. Little webapp that displays some (x, y) locations from a database, When you're done working through it, you'll have a This guide covers building a simple web-application using commonĬlojure libraries.
