-
Notifications
You must be signed in to change notification settings - Fork 519
Getting Started
Hannu Hartikainen edited this page Mar 9, 2020
·
35 revisions
Create a new project with Leiningen.
$ lein new hello-world
$ cd hello-world
Add ring-core and ring-jetty-adapter as dependencies in project.clj
.
The latest version is:
(defproject hello-world "1.0.0-SNAPSHOT"
:description "FIXME: write"
:dependencies [[org.clojure/clojure "1.9.0"]
[ring/ring-core "1.6.3"]
[ring/ring-jetty-adapter "1.6.3"]])
Download dependencies.
$ lein deps
Next, edit src/hello-world/core.clj
and add a basic handler.
(ns hello-world.core)
(defn handler [request]
{:status 200
:headers {"Content-Type" "text/html"}
:body "Hello World"})
Now we're ready to connect the handler to an adapter. Start an interactive REPL using Leiningen.
$ lein repl
Then at the REPL, run the Jetty adapter with your handler.
=> (use 'ring.adapter.jetty)
=> (use 'hello-world.core)
=> (run-jetty handler {:port 3000
:join? false})
A web server will now be running at: http://localhost:3000/.
It's a good idea to set the :join?
option is to false in REPLs. Otherwise the Jetty server will block the thread and the REPL won't process input anymore.