init api
This commit is contained in:
parent
32355ae894
commit
0f3caef7e7
3 changed files with 62 additions and 4 deletions
|
|
@ -5,4 +5,7 @@
|
||||||
:pocket-base-host "http://aemos:5000"
|
:pocket-base-host "http://aemos:5000"
|
||||||
|
|
||||||
:blue-sky-host "https://bsky.social/xrpc"
|
:blue-sky-host "https://bsky.social/xrpc"
|
||||||
:blue-sky-username "travisshears.bsky.social"}
|
:blue-sky-username "travisshears.bsky.social"
|
||||||
|
|
||||||
|
:api-host "localhost"
|
||||||
|
:api-port 3000}
|
||||||
|
|
|
||||||
14
deps.edn
14
deps.edn
|
|
@ -1,5 +1,6 @@
|
||||||
{:paths ["src"]
|
{:paths ["src"]
|
||||||
:deps {clj-http/clj-http {:mvn/version "3.13.1"}
|
:deps {;; http client
|
||||||
|
clj-http/clj-http {:mvn/version "3.13.1"}
|
||||||
;; logging
|
;; logging
|
||||||
com.taoensso/telemere {:mvn/version "1.0.0"}
|
com.taoensso/telemere {:mvn/version "1.0.0"}
|
||||||
;; schema validation
|
;; schema validation
|
||||||
|
|
@ -7,10 +8,17 @@
|
||||||
;; scheduling
|
;; scheduling
|
||||||
jarohen/chime {:mvn/version "0.3.3"}
|
jarohen/chime {:mvn/version "0.3.3"}
|
||||||
org.clojure/core.async {:mvn/version "1.8.741"}
|
org.clojure/core.async {:mvn/version "1.8.741"}
|
||||||
;; json decoding
|
;; json
|
||||||
cheshire/cheshire {:mvn/version "6.0.0"}
|
cheshire/cheshire {:mvn/version "6.0.0"}
|
||||||
;; metosin/muuntaja {:mvn/version "0.6.11"}
|
;; metosin/muuntaja {:mvn/version "0.6.11"}
|
||||||
org.clojure/clojure {:mvn/version "1.12.1"}}
|
org.clojure/clojure {:mvn/version "1.12.1"}
|
||||||
|
;; api
|
||||||
|
ring/ring-core {:mvn/version "1.13.0"}
|
||||||
|
ring/ring-jetty-adapter {:mvn/version "1.13.0"}
|
||||||
|
org.slf4j/slf4j-simple {:mvn/version "2.0.16"}
|
||||||
|
metosin/muuntaja {:mvn/version "0.6.11"}
|
||||||
|
metosin/reitit {:mvn/version "0.9.1"}}
|
||||||
|
|
||||||
:aliases
|
:aliases
|
||||||
{;; Run with clj -T:build function-in-build
|
{;; Run with clj -T:build function-in-build
|
||||||
:build {:deps {io.github.clojure/tools.build {:git/tag "v0.10.9" :git/sha "e405aac"}}
|
:build {:deps {io.github.clojure/tools.build {:git/tag "v0.10.9" :git/sha "e405aac"}}
|
||||||
|
|
|
||||||
47
src/micro_blog/api.clj
Normal file
47
src/micro_blog/api.clj
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
(ns micro-blog.api
|
||||||
|
(:require
|
||||||
|
[ring.adapter.jetty :as jetty]
|
||||||
|
[micro-blog.config :refer [config]]
|
||||||
|
[taoensso.telemere :as tel]
|
||||||
|
[muuntaja.middleware :as mm]
|
||||||
|
[ring.middleware.params]
|
||||||
|
[reitit.ring :as rr]))
|
||||||
|
|
||||||
|
(defn handle-ping [_args]
|
||||||
|
(tel/log! :info "Got ping request")
|
||||||
|
{:status 200, :body "ok"})
|
||||||
|
|
||||||
|
(defn handle-proc [{params :query-params}]
|
||||||
|
(let [id (get params "id")]
|
||||||
|
(tel/log! {:level :info :data {:id id}} "Got proc request")
|
||||||
|
{:status 200
|
||||||
|
:body :ok}))
|
||||||
|
|
||||||
|
(defn wrap [handler id]
|
||||||
|
(fn [request]
|
||||||
|
(update (handler request) :wrap (fnil conj '()) id)))
|
||||||
|
|
||||||
|
(def app
|
||||||
|
(rr/ring-handler
|
||||||
|
(rr/router
|
||||||
|
["/api" {:middleware [ring.middleware.params/wrap-params
|
||||||
|
mm/wrap-format
|
||||||
|
[wrap :api]]}
|
||||||
|
["/ping" {:get handle-ping}]
|
||||||
|
["/proc" {:get handle-proc}]])
|
||||||
|
(rr/create-default-handler)))
|
||||||
|
|
||||||
|
(defn run-server []
|
||||||
|
(let [port (@config :api-port)
|
||||||
|
host (@config :api-host)]
|
||||||
|
(jetty/run-jetty #'app {:port port :host host})))
|
||||||
|
|
||||||
|
(defn -main []
|
||||||
|
(run-server))
|
||||||
|
|
||||||
|
(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