diff --git a/README.md b/README.md index 7239ad2..da7d382 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,15 @@ App to store my code snippets. +## Links + +- [reitit docs](https://cljdoc.org/d/metosin/reitit/0.9.1/doc/introduction) +- [basic web development clojure tutorial](https://clojure-doc.org/articles/tutorials/basic_web_development/) +- [reitit malli coercion](https://cljdoc.org/d/metosin/reitit/0.9.1/doc/coercion/malli) +- [malli docs](https://github.com/metosin/malli) + ## Dev -Starting by following this guide - -https://clojure-doc.org/articles/tutorials/basic_web_development/ - ### How to run dev server ``` diff --git a/bruno/CodeSnippets/create_snippet.bru b/bruno/CodeSnippets/create_snippet.bru new file mode 100644 index 0000000..26ad351 --- /dev/null +++ b/bruno/CodeSnippets/create_snippet.bru @@ -0,0 +1,11 @@ +meta { + name: create_snippet + type: http + seq: 3 +} + +get { + url: + body: none + auth: none +} diff --git a/bruno/CodeSnippets/environments/local.bru b/bruno/CodeSnippets/environments/local.bru new file mode 100644 index 0000000..529e6ae --- /dev/null +++ b/bruno/CodeSnippets/environments/local.bru @@ -0,0 +1,3 @@ +vars { + host: http://localhost:3000 +} diff --git a/bruno/CodeSnippets/ping.bru b/bruno/CodeSnippets/ping.bru index 4808b87..7bc3b14 100644 --- a/bruno/CodeSnippets/ping.bru +++ b/bruno/CodeSnippets/ping.bru @@ -5,7 +5,7 @@ meta { } get { - url: http://localhost:3000/api/ping + url: {{host}}/api/ping body: none auth: none } diff --git a/src/snippets/api.clj b/src/snippets/api.clj index b8f29f8..f3ca2d5 100644 --- a/src/snippets/api.clj +++ b/src/snippets/api.clj @@ -4,10 +4,14 @@ [clojure.pprint :as pprint] [reitit.ring :as rr])) -(defn handler [args] +(defn handle-ping [args] (pprint/pprint args) {:status 200, :body "ok"}) +(defn handle-create-snippet [args] + (pprint/pprint args) + {:status 200, :body "snippet created"}) + (defn wrap [handler id] (fn [request] (update (handler request) :wrap (fnil conj '()) id))) @@ -16,11 +20,8 @@ (rr/ring-handler (rr/router ["/api" {:middleware [[wrap :api]]} - ["/ping" {:get handler - :name ::ping}] - ["/admin" {:middleware [[wrap :admin]]} - ["/users" {:get handler - :post handler}]]]) + ["/ping" {:get handle-ping}] + ["/snippet" {:post handle-create-snippet}]]) (rr/create-default-handler))) ;; (defroutes app-routes @@ -33,3 +34,10 @@ (defn -main [] (jetty/run-jetty #'app {:port 3000})) + +(comment + ;; evaluate this def form to start the webapp via the REPL: + ;; :join? false runs the web server in the background! + (def server (jetty/run-jetty #'app {:port 3000 :join? false})) + ;; evaluate this form to stop the webapp via the the REPL: + (.stop server))