add route handler for creating snippets
This commit is contained in:
parent
b204fbb16d
commit
524b7520d8
5 changed files with 36 additions and 11 deletions
11
README.md
11
README.md
|
|
@ -2,12 +2,15 @@
|
||||||
|
|
||||||
App to store my code snippets.
|
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
|
## Dev
|
||||||
|
|
||||||
Starting by following this guide
|
|
||||||
|
|
||||||
https://clojure-doc.org/articles/tutorials/basic_web_development/
|
|
||||||
|
|
||||||
### How to run dev server
|
### How to run dev server
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
||||||
11
bruno/CodeSnippets/create_snippet.bru
Normal file
11
bruno/CodeSnippets/create_snippet.bru
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
meta {
|
||||||
|
name: create_snippet
|
||||||
|
type: http
|
||||||
|
seq: 3
|
||||||
|
}
|
||||||
|
|
||||||
|
get {
|
||||||
|
url:
|
||||||
|
body: none
|
||||||
|
auth: none
|
||||||
|
}
|
||||||
3
bruno/CodeSnippets/environments/local.bru
Normal file
3
bruno/CodeSnippets/environments/local.bru
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
vars {
|
||||||
|
host: http://localhost:3000
|
||||||
|
}
|
||||||
|
|
@ -5,7 +5,7 @@ meta {
|
||||||
}
|
}
|
||||||
|
|
||||||
get {
|
get {
|
||||||
url: http://localhost:3000/api/ping
|
url: {{host}}/api/ping
|
||||||
body: none
|
body: none
|
||||||
auth: none
|
auth: none
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,14 @@
|
||||||
[clojure.pprint :as pprint]
|
[clojure.pprint :as pprint]
|
||||||
[reitit.ring :as rr]))
|
[reitit.ring :as rr]))
|
||||||
|
|
||||||
(defn handler [args]
|
(defn handle-ping [args]
|
||||||
(pprint/pprint args)
|
(pprint/pprint args)
|
||||||
{:status 200, :body "ok"})
|
{:status 200, :body "ok"})
|
||||||
|
|
||||||
|
(defn handle-create-snippet [args]
|
||||||
|
(pprint/pprint args)
|
||||||
|
{:status 200, :body "snippet created"})
|
||||||
|
|
||||||
(defn wrap [handler id]
|
(defn wrap [handler id]
|
||||||
(fn [request]
|
(fn [request]
|
||||||
(update (handler request) :wrap (fnil conj '()) id)))
|
(update (handler request) :wrap (fnil conj '()) id)))
|
||||||
|
|
@ -16,11 +20,8 @@
|
||||||
(rr/ring-handler
|
(rr/ring-handler
|
||||||
(rr/router
|
(rr/router
|
||||||
["/api" {:middleware [[wrap :api]]}
|
["/api" {:middleware [[wrap :api]]}
|
||||||
["/ping" {:get handler
|
["/ping" {:get handle-ping}]
|
||||||
:name ::ping}]
|
["/snippet" {:post handle-create-snippet}]])
|
||||||
["/admin" {:middleware [[wrap :admin]]}
|
|
||||||
["/users" {:get handler
|
|
||||||
:post handler}]]])
|
|
||||||
(rr/create-default-handler)))
|
(rr/create-default-handler)))
|
||||||
|
|
||||||
;; (defroutes app-routes
|
;; (defroutes app-routes
|
||||||
|
|
@ -33,3 +34,10 @@
|
||||||
|
|
||||||
(defn -main []
|
(defn -main []
|
||||||
(jetty/run-jetty #'app {:port 3000}))
|
(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))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue