Liking cljdoc? Tell your friends :D

Getting Started

In this quick tutorial we’re going to run a real Clojure project, diving into the code to show how yada is used.

Our project is called 'Edge', a sample project from JUXT to show some of our libraries in action. It lives on GitHub.

We’ll clone it first, then build it, then run it, then browse the examples and even make modifications.

So let’s get going!

Clone

First let’s clone the project and change into its working directory.

git clone https://github.com/juxt/edge
cd edge/app

Build & Run

Next we build and run it, in development mode.

clojure -A:dev:build:dev/rebel

This can take up to a couple of minutes to build and run from scratch so don’t worry if you have to wait a bit before you see anything.

[Edge] Starting nREPL server
[Edge] nREPL client can be connected to port 5600
[Rebel readline] Type :repl/help for online help info
[Edge] Loading Clojure code, please wait...
Figwheel: Starting server at http://0.0.0.0:3449
Figwheel: Watching build - main
Compiling "target/public/edge.js" from ("/home/username/Projects/clj/edge/app/dev" "/home/username/Projects/clj/edge/app/test" "/home/username/Projects/clj/edge/app/aliases/rebel" "/home/username/Projects/clj/edge/app/src" "/home/username/Projects/clj/edge/app/sass" "/home/username/Projects/clj/edge/app/resources" "/home/username/Projects/clj/edge/app/assets" "/home/username/.gitlibs/libs/io.dominic/krei.alpha/02d0675365d76e81cd2392e7f397e6f278e2a118/src")...
Successfully compiled "target/public/edge.js" in 3.472 seconds.
Figwheel: Starting CSS Watcher for paths  ["target"]
[Edge] Now enter (go) to start the dev system
dev=>

Start the Server

At the 'dev⇒' prompt enter '(go)' to start a server listening by default on port 3000.

dev=> (go)
[Edge] Website can be browsed at http://localhost:3000/
[Edge] Now make code changes, then enter (reset) here
:started

Browse

Fire up a browser and browse to http://localhost:3000/hello. You should see a simple Hello World message.

Working with the REPL

We’re going to start changing some of Edge’s source code soon, and when we do that we’ll type (reset) on our REPL. So let’s try that now.

dev=> (reset)
:reloading (io.dominic.krei.alpha.impl.util io.dominic.krei.alpha.core edge.phonebook.db edge.lacinia edge.phonebook-app edge.selmer edge.test.system edge.phonebook edge.sources edge.hello edge.examples edge.web-server edge.system edge.examples-test edge.system-test edge.main dev user io.dominic.krei.alpha.main edge.rebel.main edge.api-test)
:resumed
dev=>

Test the service

Let’s send an HTTP request to the system to check it is working. We can use a browser to visit http://localhost:3000/hello or use curl if you have it installed on your system:

curl http://localhost:3000/hello

The result should be the same:

Hello World!

Locate the source code

Fire up an editor and load up the file src/edge/hello.clj.

Locate the function called hello-routes. This returns a simple route structure that matches on the URI paths of incoming HTTP requests.

(defn hello-routes [_]
  ["/hello" (yada/handler "Hello World!\n")])

Make a change to string "Hello World!", for example, change it to "Hello Wonderful World!".

Reset the system

Now we’ve made a change to Edge’s source code, we must tell the system to reset. The system will then detect all the code changes and necessary dependencies to reload.

dev=> (reset)
:reloading (io.dominic.krei.alpha.impl.util io.dominic.krei.alpha.core edge.phonebook.db edge.lacinia edge.phonebook-app edge.selmer edge.test.system edge.phonebook edge.sources edge.hello edge.examples edge.web-server edge.system edge.examples-test edge.system-test edge.main dev user io.dominic.krei.alpha.main edge.rebel.main edge.api-test)
:resumed
dev=>

Let’s test the service again:

$ curl http://localhost:3000/hello

You should now see that the change has been made:

Hello Wonderful World!

Congratulations. You’re all up and running with a project built with yada. This will make a great lab to try out your own yada experiments and see what is possible.

Browse to http://localhost:3000 and have fun!

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close