introduction to web application development in clojure

28
Web Application Development in Clojure Jacek Laskowski @JacekLaskowski blog.japila.pl Kiev, Ukraine, 24.05.2013

Upload: jacek-laskowski

Post on 25-May-2015

1.865 views

Category:

Technology


1 download

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

Page 1: Introduction to Web Application Development in Clojure

Web Application Development

in Clojure

Jacek Laskowski @JacekLaskowski

blog.japila.pl

Kiev, Ukraine, 24.05.2013

Page 2: Introduction to Web Application Development in Clojure

Map data structure in Clojure

Symbol “m” points at the map

Page 3: Introduction to Web Application Development in Clojure

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

Page 4: Introduction to Web Application Development in Clojure
Page 5: Introduction to Web Application Development in Clojure

“Functional” request

http://localhost:8090/

Page 6: Introduction to Web Application Development in Clojure

“Functional” response

Page 7: Introduction to Web Application Development in Clojure

Leiningen• Automating Clojure

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

Page 8: Introduction to Web Application Development in Clojure

Project setup

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

Page 9: Introduction to Web Application Development in Clojure

Ring• Clojure library for web

application development• HTTP abstraction = HTTP

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

clojure/ring

Page 10: Introduction to Web Application Development in Clojure
Page 11: Introduction to Web Application Development in Clojure

Project’s project.clj

• Ring 1.2.0 Beta 3• Clojure 1.5.1

Page 12: Introduction to Web Application Development in Clojure

Project setup cont.

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

Page 13: Introduction to Web Application Development in Clojure

“Functional” response

Page 14: Introduction to Web Application Development in Clojure
Page 15: Introduction to Web Application Development in Clojure

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

• ring.handler.dump• handle-dump

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

Page 16: Introduction to Web Application Development in Clojure

Responds differently based on the URI of a request

What does the handler do?

Page 17: Introduction to Web Application Development in Clojure

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

functions• http://compojure.org/

Page 18: Introduction to Web Application Development in Clojure
Page 19: Introduction to Web Application Development in Clojure

Project’s project.clj cont.

• Compojure 1.1.5• Ring 1.2.0 Beta 3• Clojure 1.5.1

Page 20: Introduction to Web Application Development in Clojure

Project setup cont.

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

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

Page 21: Introduction to Web Application Development in Clojure
Page 22: Introduction to Web Application Development in Clojure

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

• compojure.handler• api• site

Page 23: Introduction to Web Application Development in Clojure

Generates HTML pages based on the URI of a request

What does the app do?

Page 24: Introduction to Web Application Development in Clojure

Enlive• Clojure library for web

templates• Enlive template is a HTML file

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

enlive

Page 25: Introduction to Web Application Development in Clojure
Page 26: Introduction to Web Application Development in Clojure

Project’s project.clj cont.

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

Page 28: Introduction to Web Application Development in Clojure

Pitannja?Jacek

Laskowski @JacekLaskowskiblog.japila.pl

Kiev, Ukraine, 24.05.2013