Database Reference
In-Depth Information
3.
Now that we have a namespace for it, we need to tell Ring where our web application
is. We've actually already done this. If you look toward the bottom of the project.
clj ile, you'll ind this line:
:ring {:handler web-viz.web/app}
Serving data
For this recipe, we'll serve the JSON dataile statically. By default, Ring serves static iles out
of the /resources directory of our project. In this case, create the /resources/data
directory and put the dataile that you downloaded from http://www.ericrochester.
com/clj-data-analysis/data/census-race.json into it.
Deining routes and handlers
Now, we can connect the IBM dataset to the Internet. To do this, perform the following steps:
1.
In the src/web_viz/web.clj ile, we'll deine the routes using Compojure's
defroutes macro, as shown here:
(defroutes
site-routes
(GET "/" [] (redirect "/data/census-race.json"))
(route/resources "/")
(route/not-found "Page not found"))
This creates a GET request that redirects to our dataile. It also deines routes to
serve any static resources from the classpath—in this case, to serve the resources
directory—and a 404 (resource missing) page.
2.
We use these routes as the basis of our web app:
(def app
(-> (handler/site site-routes)
(wrap-file "resources")
(wrap-file-info)
(wrap-content-type)))
Along with serving the routes we deined, this function adds more functionality to our web
app. We serve static iles from the resources directory ( wrap-file ). We add content-type
and other HTTP headers whenever we serve iles ( wrap-file-info ). Also, we make sure
to always include a content-type header, even if it's just an application/octet-stream
( wrap-content-type ).
 
Search WWH ::




Custom Search