Add an embedded web application serverλ︎
The status monitor service runs on top of an application server which handles the infrastructure of messaging over https and other Internet protocols.
There are several libraries to provide this, ring and http-kit being the most common.
Add dependencies for application server and routingλ︎
deps.edn file for the project.
Add the http-kit library library for the application server
Add the compojure library for routing of requests
Add code to start the application serverλ︎
Include the http-kit server namespace and the compojure core namespace as requires in the
Add an atom to hold a reference to the running application server. When the server is not running, the atom contains
-main function to start the application server using http-kit
run-server, optionally setting the port number the server should run on.
Define a default route and handlerλ︎
Using the compojure
defroutes function, define the default route and response when the status-monitor app received a request on the main URL, (eg. http://localhost:8888/)
The route returns a hash-map that is the form of a response map. http-kit server transforms all response maps into https responses that are sent back to the requesting web browser.
Stop and restart server from REPLλ︎
Add functions to stop and restart the server, so change to the application code can be loaded in without having to stop the Clojure REPL.
Use the value in the app-server-instance atom to determine if the app-server is already running. If so, then send the instance the
:timeout key with a value of time to shut itself down.
With a REPL running the project, the server is started calling
(-main) and stopped by calling
(stop-app-server). A restart function is simply calling the stop and start functions.
Component lifecycle service
REPL experiment sectionλ︎
To help use the code during development a comment body has been included with calls to start, stop and restart the application.