@@ -118,15 +118,15 @@ components:
118
118
A clojure map of OperationId to handler fns:
119
119
` ` ` clojure
120
120
(def handlers
121
- {"AddGet" (fn [{{{:keys [n1 n2]} :path} :parameters}]
122
- {:status 200
123
- :body (str (+ n1 n2))})
124
- " AddPost" (fn [{{{:keys [n1 n2]} :body} :parameters}]
125
- {:status 200
126
- :body (str (+ n1 n2))})
121
+ {"AddGet" (fn [{{{:keys [n1 n2]} :path} :parameters}]
122
+ {:status 200
123
+ :body (str (+ n1 n2))})
124
+ " AddPost" (fn [{{{:keys [n1 n2]} :body} :parameters}]
125
+ {:status 200
126
+ :body (str (+ n1 n2))})
127
127
" HealthCheck" (fn [_]
128
128
{:status 200
129
- :body "Ok"})})
129
+ :body "Ok"})})
130
130
```
131
131
132
132
Generate the routes:
@@ -156,58 +156,64 @@ Generate the routes:
156
156
157
157
Bootstrapping a Jetty server:
158
158
``` clojure
159
- (ns server
160
- (:require [muuntaja.core :as m]
161
- [reitit.ring :as ring]
162
- [reitit.http :as http]
163
- [reitit.coercion.malli :as malli]
164
- [reitit.http.coercion :as coercion]
165
- [reitit.http.interceptors.parameters :as parameters]
166
- [reitit.http.interceptors.muuntaja :as muuntaja]
167
- [reitit.interceptor.sieppari :as sieppari]
168
- [ring.adapter.jetty :as jetty]
169
- [navi.core :as navi]))
159
+ (ns server.main
160
+ (:require
161
+ [muuntaja.core :as m]
162
+ [navi.core :as navi]
163
+ [reitit.coercion.malli :as malli]
164
+ [reitit.http :as http]
165
+ [reitit.http.coercion :as coercion]
166
+ [reitit.http.interceptors.exception :as exception]
167
+ [reitit.http.interceptors.muuntaja :as muuntaja]
168
+ [reitit.http.interceptors.parameters :as parameters]
169
+ [reitit.interceptor.sieppari :as sieppari]
170
+ [reitit.ring :as ring]
171
+ [ring.adapter.jetty :as jetty])
172
+ (:gen-class ))
170
173
171
174
(def server
172
175
(http/ring-handler
173
- (http/router (-> " api.yaml"
174
- slurp
175
- (navi/routes-from handlers)) ; handlers is the map described before
176
- {:data {:coercion malli/coercion
177
- :muuntaja m/instance
178
- :interceptors [(parameters/parameters-interceptor )
179
- (muuntaja/format-negotiate-interceptor )
180
- (muuntaja/format-response-interceptor )
181
- (exception/exception-interceptor )
182
- (muuntaja/format-request-interceptor )
183
- (coercion/coerce-exceptions-interceptor )
184
- (coercion/coerce-response-interceptor )
185
- (coercion/coerce-request-interceptor )]}})
186
- (ring/routes
187
- (ring/create-default-handler
188
- {:not-found (constantly {:status 404
189
- :headers {" Content-Type" " application/json" }
190
- :body " {\" message\" : \" Took a wrong turn?\" }" })}))
191
- {:executor sieppari/executor}))
192
-
193
- (jetty/run-jetty (var server)
194
- {:host " 0.0.0.0"
195
- :port 7777
196
- :join? false
197
- :async? true })
176
+ (http/router (-> " api.yaml"
177
+ slurp
178
+ (navi/routes-from handlers)) ; handlers is the map described before
179
+ {:data {:coercion malli/coercion
180
+ :muuntaja m/instance
181
+ :interceptors [(parameters/parameters-interceptor )
182
+ (muuntaja/format-negotiate-interceptor )
183
+ (muuntaja/format-response-interceptor )
184
+ (exception/exception-interceptor )
185
+ (muuntaja/format-request-interceptor )
186
+ (coercion/coerce-exceptions-interceptor )
187
+ (coercion/coerce-response-interceptor )
188
+ (coercion/coerce-request-interceptor )]}})
189
+ (ring/routes
190
+ (ring/create-default-handler
191
+ {:not-found (constantly {:status 404
192
+ :headers {" Content-Type" " application/json" }
193
+ :body " {\" message\" : \" Took a wrong turn?\" }" })}))
194
+ {:executor sieppari/executor}))
195
+
196
+ (defn -main
197
+ [& _]
198
+ (jetty/run-jetty (var server)
199
+ {:host " 0.0.0.0"
200
+ :port 7777
201
+ :join? false
202
+ :async? true }))
198
203
```
199
204
200
205
deps.edn used for this example:
201
206
``` edn
202
207
{:deps {org.clojars.lispyclouds/navi {:mvn/version " 0.0.2" }
203
- metosin/reitit-core {:mvn/version " 0.6.0" }
204
- metosin/reitit-http {:mvn/version " 0.6.0" }
205
- metosin/reitit-interceptors {:mvn/version " 0.6.0" }
206
- metosin/reitit-malli {:mvn/version " 0.6.0" }
207
- metosin/reitit-ring {:mvn/version " 0.6.0" }
208
- metosin/reitit-sieppari {:mvn/version " 0.6.0" }
209
- metosin/muuntaja {:mvn/version " 0.6.8" }
210
- ring/ring-jetty-adapter {:mvn/version " 1.9.2" }}}
208
+ metosin/reitit-core {:mvn/version " 0.6.0" }
209
+ metosin/reitit-http {:mvn/version " 0.6.0" }
210
+ metosin/reitit-interceptors {:mvn/version " 0.6.0" }
211
+ metosin/reitit-malli {:mvn/version " 0.6.0" }
212
+ metosin/reitit-ring {:mvn/version " 0.6.0" }
213
+ metosin/reitit-sieppari {:mvn/version " 0.6.0" }
214
+ metosin/reitit-middleware {:mvn/version " 0.6.0" }
215
+ metosin/muuntaja {:mvn/version " 0.6.8" }
216
+ ring/ring-jetty-adapter {:mvn/version " 1.9.6" }}}
211
217
```
212
218
213
219
### Build Requirements
@@ -219,6 +225,6 @@ deps.edn used for this example:
219
225
220
226
## License
221
227
222
- Copyright © 2020-2021 Rahul De
228
+ Copyright © 2020- Rahul De
223
229
224
- Distributed under the EPL License, same as Clojure . See LICENSE.
230
+ Distributed under the MIT License. See LICENSE.
0 commit comments