introduction to web application development in clojure

Post on 25-May-2015

1.865 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

My presentation about web application development with Clojure, Ring, Compojure and Enlive that I gave at JEEConf in Kiev, Ukraine - http://jeeconf.com/.

TRANSCRIPT

Web Application Development

in Clojure

Jacek Laskowski @JacekLaskowski

blog.japila.pl

Kiev, Ukraine, 24.05.2013

Map data structure in Clojure

Symbol “m” points at the map

Map in Clojure• Map maps keys to values• Maps are functions of their

keys• Keywords usually keys• assoc to add key and value• dissoc to remove keys

“Functional” request

http://localhost:8090/

“Functional” response

Leiningen• Automating Clojure

projects with Clojure• lein help when in trouble• http://leiningen.org/

Project setup

• lein new jeeconf-clojure-webapp• cd jeeconf-clojure-webapp• Configure project in project.clj• ...more soon

Ring• Clojure library for web

application development• HTTP abstraction = HTTP

requests are Clojure maps• https://github.com/ring-

clojure/ring

Project’s project.clj

• Ring 1.2.0 Beta 3• Clojure 1.5.1

Project setup cont.

• lein repl• (use 'ring.adapter.jetty)• (run-jetty handler options)• (doc run-jetty) when in trouble

“Functional” response

Ring Utils• ring.util.response• response• not-found

• ring.handler.dump• handle-dump

• ring.middleware.stacktrace• wrap-stacktrace-web

Responds differently based on the URI of a request

What does the handler do?

Compojure• Clojure library for web routing• DSL to generate Ring handler

functions• http://compojure.org/

Project’s project.clj cont.

• Compojure 1.1.5• Ring 1.2.0 Beta 3• Clojure 1.5.1

Project setup cont.

• lein repl• (use 'ring.adapter.jetty)• (run-jetty handler options)

• (use ‘compojure.core)• (defroutes)• GET et al.

Compojure Utils• compojure.route• files• not-found• resources

• compojure.handler• api• site

Generates HTML pages based on the URI of a request

What does the app do?

Enlive• Clojure library for web

templates• Enlive template is a HTML file

and a deftemplate form• https://github.com/cgrand/

enlive

Project’s project.clj cont.

• Enlive 1.1.1• Compojure 1.1.5• Ring 1.2.0 Beta 3• Clojure 1.5.1

Pitannja?Jacek

Laskowski @JacekLaskowskiblog.japila.pl

Kiev, Ukraine, 24.05.2013

top related