reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
amarus 2020-04-26T01:15:44.193500Z

Hi! Does someone have example simple frontend-backend CRUD project with reitit? I cannot understand how to interact from frontend to backend rest api. May I just use simple http requests from frontend route handlers to bakend?

bartuka 2020-04-26T02:53:54.194300Z

hi @alishermatkurbanov040, in the oficial repository has some examples there, have you looked at? https://github.com/metosin/reitit/tree/master/examples/frontend

lsenjov 2020-04-26T03:00:27.195200Z

Reitit itself doesn't do much by itself, but it's a useful library to be used by other parts

mkvlr 2020-04-26T08:56:15.195800Z

A good chunk of our frontend init time is spent creating the router. We have a total of 130 routes and quite a few of them conflict since we have github-style routes /:profile-handle/:article-name which predate us switching to reitit. Is there a way to do this work ahead of time?

orestis 2020-04-26T09:36:54.199200Z

Oh wow. I was wondering if the performance trade offs reitit makes apply also to front end. Seems like the performance focus for frontend should rather be to amortize the cost over time, rather than at init time. Still, you have to somehow route at init too so not sure about ways to optimize this.

orestis 2020-04-26T09:37:19.199800Z

@mkvlr how many routes are you dealing with?

mkvlr 2020-04-26T10:45:12.200200Z

@orestis 130 total

ikitommi 2020-04-26T10:49:24.203600Z

Looking at the code, the conflict resolution is run twice, should be easy win to fix that. Also, there doesn't seem to be a way to totally disable the conflict resolution, one could just use linear-router and get fast startup and bit slower routing.

ikitommi 2020-04-26T10:50:45.205300Z

If you define the router via def, shouldn't it be precalculated?

ikitommi 2020-04-26T10:54:45.208600Z

I could fix the two small things later today. The router creation is not perf optimized currently ..

mkvlr 2020-04-26T10:56:57.209500Z

I do have the router defined in a def

mkvlr 2020-04-26T10:58:55.211Z

being able to specify the router implementation as an opt would go good for our use case I guess

mkvlr 2020-04-26T10:59:45.212300Z

seems it should be possible with the public api also, but I must have done something wrong when I tried

mkvlr 2020-04-26T11:02:02.213800Z

no rush at all btw, we’ve lived with this for a while, just recently discovered it and thought I’d ask

Marcus 2020-04-26T18:42:07.216900Z

Hello all! I'm fairly new to clojure and reitit. I am trying to set up a ring/swagger service. Is there a way to have the default edn in both requests and responses? When I do a request now with accept = application/edn I still get a application/json response that must be decoded. E.g. {:status 200, :body #object[http://java.io.ByteArrayInputStream 0x68a954f9 "http://java.io.ByteArrayInputStream@68a954f9"], :headers {"Content-Type" "application/json; charset=utf-8"}}.

ikitommi 2020-04-26T19:18:39.219300Z

@marcus.akre could you paste the request you are sending? if accept is edn, it should return it in that.

ikitommi 2020-04-26T19:19:24.220100Z

@mkvlr did a small spike on router creation perf. It’s crap 🙂 Here’s a PR for making it bit better: https://github.com/metosin/reitit/pull/389

ikitommi 2020-04-26T19:22:25.221100Z

98% of the time is spent here: https://github.com/metosin/reitit/blob/master/modules/reitit-core/src/reitit/impl.cljc#L76-L84, PR welcome to make it faster.

ikitommi 2020-04-26T19:22:38.221400Z

Marcus 2020-04-26T19:25:39.222300Z

@ikitommi

(app {:request-method :get
    :uri "/plus"
      :query-params {:x 1 :y 2}}
     ))

Marcus 2020-04-26T19:25:43.222500Z

and

Marcus 2020-04-26T19:25:47.222800Z

:swagger {:produces #{"application/edn"}
                        :consumes #{"application/edn"}}

Marcus 2020-04-26T19:26:05.223300Z

in the swagger ui the only option is edn

Marcus 2020-04-26T19:26:36.223900Z

If I query with accept = edn it works fine. actually

Marcus 2020-04-26T19:26:51.224200Z

(via http client that is)

mkvlr 2020-04-26T19:31:17.225Z

@ikitommi thank you! Will give it a try tomorrow and let you know. Thanks again!