Advertisement
Guest User

Untitled

a guest
May 22nd, 2021
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (ns ring-todo-list.core
  2.   (:require [reitit.ring :as ring]
  3.             [reitit.ring.coercion :as coercion]
  4.             [reitit.coercion.schema]
  5.             [schema.core :as s]
  6.             [ring.middleware.reload :refer [wrap-reload]]
  7.             [ring.adapter.jetty :refer [run-jetty]]
  8.             [reitit.ring.middleware.muuntaja :as muuntaja]
  9.             [muuntaja.core :as m]
  10.             ))
  11.  
  12. (def app
  13.   (ring/ring-handler
  14.     (ring/router
  15.       [
  16.        ["/api/v1/todo-list"
  17.         [""
  18.          {:post
  19.           {:handler
  20.            (fn [{{:keys [todo-list]} :body-params}]         ;{{:keys [x y]} :body-params}
  21.              {:status 200
  22.               :body   todo-list
  23.               })
  24.            }
  25.           :get
  26.           {:handler
  27.            (fn [_]
  28.              {:status 200
  29.               :body   {:todo-list [{:id 2 :text "Do something"}]}
  30.               })
  31.            }
  32.           }]
  33.         ["/:id"
  34.          {:get
  35.           {:coercion reitit.coercion.schema/coercion
  36.            :parameters {:path {:id s/Int}}
  37.            :handler
  38.                        (fn [{{:keys [id]} :path-params}]
  39.                          {:status 200
  40.                           :body   {:id id :todo-list [{:id 2 :text "Do something else"}]}
  41.                           })}}]
  42.         ]
  43.        ]
  44.  
  45.       {:data {
  46.               :muuntaja   m/instance
  47.               :middleware [muuntaja/format-middleware
  48.                            coercion/coerce-exceptions-middleware
  49.                            coercion/coerce-request-middleware
  50.                            coercion/coerce-response-middleware]
  51.               }})))
  52.  
  53. (defn -main [& args]
  54.   (run-jetty
  55.     (-> app
  56.         var
  57.         wrap-reload)
  58.     {:port 3000}))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement