Putting It All Together

Let’s look at an example of a service that has a couple of resources that allow the client to read and write some data. The application will display a list of to-do items and allow the user to add additional items to the list.

The client will be implemented in ClojureScript and use Ajax to communicate with the service. The client code will consist of a few functions to retrieve, render, and save to-do items. Let’s look at each of these in turn.

The first function renders the items in our list.

 (​defn​ item-list [items]
  (when (not-empty items)
  [:ul
  (​for​ [item items]
  ^{:key item}
  [:li item])]))

Next we add a function called get-items to grab the items ...

Get Web Development with Clojure, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.