In the Wild

You can find a great example of clojure.spec in action in the ring-spec,[27] which contains specs for the Ring web application library. For example, as we saw back in Chapter 6, Functional Things, a key part of a Ring application is dealing with requests, which arrive at the application in the form of maps. But what, exactly, do those request maps contain?

I’m glad you asked:

 (s/def :ring/request
  (s/keys :req-un [:ring.request/server-port
  :ring.request/server-name
  :ring.request/remote-addr
  :ring.request/uri
  :ring.request/scheme
  :ring.request/protocol
  :ring.request/headers
  :ring.request/request-method]
  :opt-un [:ring.request/query-string
  :ring.request/body]))

Looks like we have a map with entries for port, a ...

Get Getting Clojure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.