A small example project in Clojure. Fetches train information from rata.digitraffic.fi API and displays it.
- Install the Clojure build tool Leiningen.
- Run
lein ring server
to start the server and a browser - Change the code (file
src/handler.clj
) - Refresh the browser and see your changes
project.clj
: the configuration file for Leiningensrc/handler.clj
: the code is hereresources/public/style.css
: the CSS style filetest/handler_test.clj
: unit tests (run these withlein test
)
- ClojureDocs – the Clojure standard library documentation, searchable
- Compojure wiki – the web framework used in this project
- Hiccup wiki - how to generate HTML
- clj-time - how to handle time
- docs for the digitraffic api
- make the page prettier
- make the station configurable
- show only time table rows for this station
- only show future events
- collect statistics of late trains
Interactive development means having a REPL (command prompt) where you can interact with the code and try out things, while also running the server.
Here's how:
- Start an interactive clojure environment, for example:
- run
lein repl
in a terminal - use
M-x cider-jack-in
in Emacs (after installing cider) - install a Clojure IDE like Cursive for IntelliJ
- run
- Run
(run)
to start a server - Try out things and edit code
- Reload code changes with either
- the reload functionality in your IDE
- running
(refresh)
in the repl
In case you don't feel like installing a Clojure IDE or editor, you can try out the browser-based editor, Nightlight:
- Run
lein nightlight
- Point your broser to http://localhost:4000
- Open the file
src/handler.clj
- You can run the server like this:
- Switch to Clojure REPL (on the top left)
- Type in
(handler/run)
- Open another browser tab to http://localhost:3000
TODO