Skip to content

Commit

Permalink
[housekeeping] more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lispyclouds committed Feb 22, 2023
1 parent c6cd2cc commit 4fa81c4
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 57 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

name: Tests

on: [push]
on:
push:
paths-ignore:
- "**.md"

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018-2022 Rahul De
Copyright (c) 2020- Rahul De

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
112 changes: 59 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ components:
A clojure map of OperationId to handler fns:
```clojure
(def handlers
{"AddGet" (fn [{{{:keys [n1 n2]} :path} :parameters}]
{:status 200
:body (str (+ n1 n2))})
"AddPost" (fn [{{{:keys [n1 n2]} :body} :parameters}]
{:status 200
:body (str (+ n1 n2))})
{"AddGet" (fn [{{{:keys [n1 n2]} :path} :parameters}]
{:status 200
:body (str (+ n1 n2))})
"AddPost" (fn [{{{:keys [n1 n2]} :body} :parameters}]
{:status 200
:body (str (+ n1 n2))})
"HealthCheck" (fn [_]
{:status 200
:body "Ok"})})
:body "Ok"})})
```

Generate the routes:
Expand Down Expand Up @@ -156,58 +156,64 @@ Generate the routes:

Bootstrapping a Jetty server:
```clojure
(ns server
(:require [muuntaja.core :as m]
[reitit.ring :as ring]
[reitit.http :as http]
[reitit.coercion.malli :as malli]
[reitit.http.coercion :as coercion]
[reitit.http.interceptors.parameters :as parameters]
[reitit.http.interceptors.muuntaja :as muuntaja]
[reitit.interceptor.sieppari :as sieppari]
[ring.adapter.jetty :as jetty]
[navi.core :as navi]))
(ns server.main
(:require
[muuntaja.core :as m]
[navi.core :as navi]
[reitit.coercion.malli :as malli]
[reitit.http :as http]
[reitit.http.coercion :as coercion]
[reitit.http.interceptors.exception :as exception]
[reitit.http.interceptors.muuntaja :as muuntaja]
[reitit.http.interceptors.parameters :as parameters]
[reitit.interceptor.sieppari :as sieppari]
[reitit.ring :as ring]
[ring.adapter.jetty :as jetty])
(:gen-class))

(def server
(http/ring-handler
(http/router (-> "api.yaml"
slurp
(navi/routes-from handlers)) ; handlers is the map described before
{:data {:coercion malli/coercion
:muuntaja m/instance
:interceptors [(parameters/parameters-interceptor)
(muuntaja/format-negotiate-interceptor)
(muuntaja/format-response-interceptor)
(exception/exception-interceptor)
(muuntaja/format-request-interceptor)
(coercion/coerce-exceptions-interceptor)
(coercion/coerce-response-interceptor)
(coercion/coerce-request-interceptor)]}})
(ring/routes
(ring/create-default-handler
{:not-found (constantly {:status 404
:headers {"Content-Type" "application/json"}
:body "{\"message\": \"Took a wrong turn?\"}"})}))
{:executor sieppari/executor}))

(jetty/run-jetty (var server)
{:host "0.0.0.0"
:port 7777
:join? false
:async? true})
(http/router (-> "api.yaml"
slurp
(navi/routes-from handlers)) ; handlers is the map described before
{:data {:coercion malli/coercion
:muuntaja m/instance
:interceptors [(parameters/parameters-interceptor)
(muuntaja/format-negotiate-interceptor)
(muuntaja/format-response-interceptor)
(exception/exception-interceptor)
(muuntaja/format-request-interceptor)
(coercion/coerce-exceptions-interceptor)
(coercion/coerce-response-interceptor)
(coercion/coerce-request-interceptor)]}})
(ring/routes
(ring/create-default-handler
{:not-found (constantly {:status 404
:headers {"Content-Type" "application/json"}
:body "{\"message\": \"Took a wrong turn?\"}"})}))
{:executor sieppari/executor}))

(defn -main
[& _]
(jetty/run-jetty (var server)
{:host "0.0.0.0"
:port 7777
:join? false
:async? true}))
```

deps.edn used for this example:
```edn
{:deps {org.clojars.lispyclouds/navi {:mvn/version "0.0.2"}
metosin/reitit-core {:mvn/version "0.6.0"}
metosin/reitit-http {:mvn/version "0.6.0"}
metosin/reitit-interceptors {:mvn/version "0.6.0"}
metosin/reitit-malli {:mvn/version "0.6.0"}
metosin/reitit-ring {:mvn/version "0.6.0"}
metosin/reitit-sieppari {:mvn/version "0.6.0"}
metosin/muuntaja {:mvn/version "0.6.8"}
ring/ring-jetty-adapter {:mvn/version "1.9.2"}}}
metosin/reitit-core {:mvn/version "0.6.0"}
metosin/reitit-http {:mvn/version "0.6.0"}
metosin/reitit-interceptors {:mvn/version "0.6.0"}
metosin/reitit-malli {:mvn/version "0.6.0"}
metosin/reitit-ring {:mvn/version "0.6.0"}
metosin/reitit-sieppari {:mvn/version "0.6.0"}
metosin/reitit-middleware {:mvn/version "0.6.0"}
metosin/muuntaja {:mvn/version "0.6.8"}
ring/ring-jetty-adapter {:mvn/version "1.9.6"}}}
```

### Build Requirements
Expand All @@ -219,6 +225,6 @@ deps.edn used for this example:

## License

Copyright © 2020-2021 Rahul De
Copyright © 2020- Rahul De

Distributed under the EPL License, same as Clojure. See LICENSE.
Distributed under the MIT License. See LICENSE.
4 changes: 2 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
:author "Rahul De <rahul@mailbox.org>"
:url "https://github.com/lispyclouds/navi"
:description "A tiny library converting OpenAPI route definitions to Reitit routes."
:license {:name "EPL 1.0"
:url "http://opensource.org/licenses/eclipse-1.0.php"}
:license {:name "MIT"
:url "https://opensource.org/licenses/MIT"}
:dependencies [[io.swagger.parser.v3/swagger-parser "2.1.12"]])

0 comments on commit 4fa81c4

Please sign in to comment.