Last active
June 5, 2020 21:27
-
-
Save renatoalencar/655928b1d318255361dbb6413a5a9bef to your computer and use it in GitHub Desktop.
Introducao a Clojure Component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns example-atom | |
| (:require [ring.adapter.jetty :refer [run-jetty]] | |
| [monger.core :as mg] | |
| [monger.collection :as mc])) | |
| (def database (atom nil)) | |
| (defn connect-db! [uri] | |
| (swap! database (fn [db] (-> uri | |
| mg/connect-via-uri | |
| :db)))) | |
| (defn list-users! [] | |
| (mc/find-maps @database :users)) | |
| (defn handler [request] | |
| {:status 200 | |
| :body (clojure.string/join "\n" (list-users!))}) | |
| (defn -main | |
| [& args] | |
| (connect-db! (System/getenv "DATABASE_URL")) | |
| (run-jetty handler {:port 3000})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment