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.
|
||||
|
||||
## 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
|
||||
|
||||
```
|
||||
|
|
|
|||
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 {
|
||||
url: http://localhost:3000/api/ping
|
||||
url: {{host}}/api/ping
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue