Small web application which consumes the Open Weather API and makes use of Clojure's atom
construct as cache.
Make sure you have both java
and clj
installed.
$ git clone https://github.com/tiagodalloca/city-weather-clj.git
$ cd city-weather-clj
$ chmod +x config
$ ./config
./config
will ask for your Open Weather API key and store it under resources/secrests
clj -T:build uber
java -jar target/city-weather-clj-0.1.0-standalone.jar
You should be able to interact with localhost:8989/weather/:city
, where :city
is supposed to be a city name.
Although simple in functionality, this small web application makes use of fundamental design principles that makes it easy to test, maintain and extend.
System state is managed explicitly and passed on to components via a dependency map with qualified keywords (take a look at get-handler
to see this in practice). It's easy to see how these dependencies are wired, thanks to Integrant and Aero which make system configuration declarative. Not only that, system-wide start and stop are easily implemented, and the system state is easy to track and debug, as it is unified in an atom containing a map. This principled approach reduces system components entanglement and instead favors composability.
API interaction is modelled making use of defprotocol
, so that mocking is trivial and facilitating get-city-weather-handler
's tests.
The cache is basically an atom and a map for the sake of brevity, but, because it is wrapped in a record implementing StatefulWeatherCache
, adopting a more permanent solution such as DataScript would be just a protocol implementation away.
This project was implemented making use of: