This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-06-04
Channels
- # announcements (4)
- # beginners (110)
- # boot (6)
- # calva (23)
- # cider (14)
- # cljdoc (5)
- # cljs-dev (50)
- # cljsrn (3)
- # clojure (105)
- # clojure-europe (3)
- # clojure-italy (46)
- # clojure-nl (6)
- # clojure-spec (19)
- # clojure-sweden (1)
- # clojure-uk (78)
- # clojurescript (66)
- # core-async (5)
- # cursive (19)
- # data-science (16)
- # datomic (3)
- # events (2)
- # fulcro (11)
- # hoplon (53)
- # jobs (4)
- # jobs-discuss (6)
- # keechma (51)
- # leiningen (3)
- # nrepl (25)
- # off-topic (95)
- # parinfer (8)
- # precept (1)
- # reitit (61)
- # remote-jobs (1)
- # rewrite-clj (75)
- # ring-swagger (2)
- # robots (3)
- # shadow-cljs (43)
- # tools-deps (28)
- # vim (2)
Hi all
Question:
I know the responses (swagger) are written like this:
:responses {200 {:body {:total string?}}}
I'd like to know how to specify multiple responses for the same endpoint, ex. when the request returns another status, for example, 401
@comparalf just add a new response code under :responses
, e.g. {200 ..., 401 ...}
there is also :default
key. see the docs: https://swagger.io/docs/specification/2-0/describing-responses/
only thing that spec-tools & schema-tools do there is to convert the :body
definition into Swagger :schema
@stefan.age sorry, no docs, but . Would be great to have a tutorial for the frontend. the there is a sample in https://github.com/metosin/reitit/tree/master/examples/frontend-links
not directly related to reitit, but building a wrapper for reactive / non-blocking sql client for clojure, will work oob with reitit-http
thanks to sieppari, uses vertx-sql-client under the hoods:
(require '[porsas.async :as pa])
(require '[promesa.core :as p])
(def pool
(pa/pool
{:uri ""
:user "benchmarkdbuser"
:password "benchmarkdbpass"}))
(def mapper (pa/data-mapper))
(-> (pa/query-one mapper pool ["SELECT randomnumber from WORLD where id=$1" 1])
(p/chain :randomnumber inc inc)
(p/bind println))
; => #<Promise[~]>
; prints 2839
Hi when using reitit-pedestal I found something that seems incorrect the routing interceptor from reitit-http
matches on :uri
but the normal pedestal router matches on :path-info
. This only hits me because we are adding pedestal to a servlet and trying out reitit. But our servlet has a context path for our case it's /jira
So this would mean I would need to add /jira
to all of my routes, but this could be anything because it is configurable
I fixed it by creating an interceptor for pedestal:
(def fix-reitit-matching
(io.pedestal.interceptor/interceptor
{:name ::fix-reitit-matching
:enter (fn [context]
(assoc-in context [:request :uri] (get-in context [:request :path-info])))}))
yes, there is nothing for servlets for now. I guess the swagger-docs are also off because of that.
haven’t used them in years, but remember the same uri patching done in compojure-api & ring-swagger.
Basically constraints, we are writing a JIRA addon with clojure. And you have the possibility to mount servlets from addons
So we create a big jar and Jira loads it and parses some xml and voila we get mounted under a certain servlet path
Swagger was my next step, but you don't think that that is possible?
btw this is exactly what happens:
:path-info "/plugins/servlet/atlascrm/api/contact/1",
:context-path "/jira",
:uri "/jira/plugins/servlet/atlascrm/api/contact/1",
Btw we are not married to Pedestal, so if I could do this some other way we would also be interested
Ah I see we could also look at ring-servlet, not sure if pedestal is worth the trouble for our use case
Thank you @ikitommi, I had an extra {200 fncall} around the response too
@mitchelkuijpers do you need to strip out the :context-path
from :uri
or add that in? in the example :uri
has it, but :path-info
doesn’t
for swagger, there is route data {:swagger {:basePath "/jira"}}
which indicates that /jira
need to be concatenated to all paths.
I need to strip it out when matching
Yes pedestal did that for us
if you know the context at router creation time, it would be easy just to add the :path
option to router, e.g:
(-> (r/router
["/kikka"]
{:path "/jira"})
(r/routes))
;=> [["/jira/kikka" {}]]
if that’s dynamic, you need to do the runtime uri-conversion (as you have) and hint both the swagger-ui & reverse-routing to do the same in reverse.
Ah yeah it could be dynamic, you can expose them on a context path and on another one
I think I am also going to look at ring-servlet, it seems reitit does mostly everything that pedestal does but better documented
Then I'll rather have a real easy layer inbetween
Sure, thank you for listening
Nice, it works way simpler with ring-servlet
Btw in ring I get: servlet-context-path "/jira"
so I think it should be possible to create some simple helpers
Now we are running into fun situations with for example (ring/redirect-trailing-slash-handler)
Would you accept some sort of PR for adding a concept of context or something along the lines?
@mitchelkuijpers sure thing, maybe start with a quick draft first to see all the places it effects? and a zero perf penalty for cases it’s not used.
Good one, will take a while will first work around it, I have some deadlines, maybe it is solvable with some small helpers around
For example I could copy the redirect-trailing-slash-handler for now
Or wrap it
I can imagine this simply not being a very interesting case for some folks
Yeah, but we are very happy that it is possible
Otherwise we would be doing Java and Spring
sure, I think the changes will be subtle, most likely an new option into reitit.ring/ring-handler
or reitit.ring/router
.
+ some code reading it in few places. could you write an issue out of that so people can find it later?
My company is considering adopting reitit
(switching off of Compojure). In playing around with the lib, we were having difficulty getting query parameter data to show up when matching on path. Basically something like /foo
would would match correctly. However /foo?hello=world
would return nil
when attempting to match. I'm guessing that we need to include additional data during route creation but I was not able to find any examples of this in the documentation.
@mafcocinco welcome! ring specifies the :uri
not to contain the query-string, which should be separately in the :query-string
. All the ring-adapters I know do this. Where do you get that uri?
Just calling match-by-path
in the REPL. So it seems reitit
expects the URI that ring
produces, i.e. already parsed with query params removed.
roger. Thank you for your help.
One followup and this could just be my ignorance of frontend development: How does this work in the context of a re-frame
or other CLJS application? AFAIK, Ring is a server side library but reitit
can be used for front end routing (and we are planning to use it from both FE and BE). Is this the point of the reitit.frontend.*
namespaces?
yes, the reitit-frontend
should be idiomatic with js/cljs, while reitit-ring
is with ring. Frontend doesn't have as much docs but hopefully the examples help
@mafcocinco maybe this could help you to figure out the way.. (it's based in the example) it's kind a short summary haaha it's with re-frame
(def pages
{:login [login-page]
:main [main-page]})
(def router
(reitit/router
[["/" :main]
["/login" :login]
]))
(defn main-layout []
(r/with-let [active-page (subscribe [:active-page])
user (subscribe [:user])]
[:div
(if @user
[:div
(pages @active-page user)]
(pages :login nil))
[:pre (with-out-str (fedn/pprint user))]]))
the hook-browser-navigation! very importantUsing the above setup, any idea why /graphiql
or /foobar
always renders the home component?
when you don't have an idea what is clojure, the most simplest thing takes a long time haahaha