Fork me on GitHub
#reitit
<
2019-07-09
>
ikitommi06:07:31

@grzegorzrynkowski_clo mw are applied in the order they are defined, and the order can matter. For example, the content-negotiation needs to happen before request or response formatting.

ikitommi06:07:17

mw could be reordered automatically based on their requirements, there is a helpers to build such a dependency system.

Greg Rynkowski09:07:43

@ikitommi re the mw order: 1. in this case, shouldn’t parameters parameters/parameters-middleware in the ring-spec-swagger example be listed later in the vector (after the muuntaja entries)? (https://github.com/metosin/reitit/blob/master/examples/ring-spec-swagger/src/example/server.clj#L88) 2. Since the exception-middleware doesn’t react on requests directly (but in response to handlers or middlewares error), shouldn’t it be first in the vector of middlewares? (https://github.com/metosin/reitit/blob/master/examples/ring-spec-swagger/src/example/server.clj#L94)?

ikitommi11:07:05

@grzegorzrynkowski_clo the parameters-middleware is from ring and doing it's own negotiation for form parameters, so it can be in that place. There is an issue to move that too to Muuntaja (and multiparts too), do all negotiations would be in one place.

ikitommi11:07:51

it needs to be before request-coercion, which expects raw parameter maps to exist in the request

ikitommi11:07:43

have you tried the mw chain debugger? It shows what different components are doing for req/res

Greg Rynkowski11:07:04

Yes, I tried now, great tool. Thanks

Casey13:07:43

are there any examples of using reitit to handle routes for a client side http library? would such a thing work?

dharrigan14:07:12

I would suggest other libraries such as clj-http or clj-rest-client etc...

Casey15:07:02

@rgm that's not quite what I mean. That's for frontend routing in the browser, which is essentially the same concept as backend routing in a rest api. What I'm pondering is using reitit as the framework to build up a library for interacting with an existing HTTP API. Somehow using reitit defined routes to generate request maps to be passed to clj-http

rgm15:07:06

Oh I see. Sorry. Didn’t quite grok that.

rgm15:07:59

There’s an href generator in frontend.easy ... do you mean something like that? https://github.com/metosin/reitit/blob/master/examples/frontend-re-frame/src/cljs/frontend_re_frame/core.cljs

rgm15:07:20

(See line 74)

Casey15:07:35

sort of yea, that's a nice example of using reitit in a different way

ikitommi15:07:30

@ramblurr would you use reitit on the client side to describe paths in any server or a just for a reitit backend?

ikitommi15:07:50

for a reitit backend, you can use shared routes. For more dynamic system, this could be useful: https://github.com/metosin/reitit/issues/227

ikitommi15:07:15

for full integration, all the information (parameters, auth) should be exposed. Swagger is providing one such tool...

Casey15:07:03

In this particular case it would be to describe paths of a non-reitit backend. However for other scenarios we have, using it against a reitit backend would also be useful

Casey15:07:58

for this particular task I'm working on, I have a rather large and complicated third-party http api, and I want to define it as data, then be able to operate on it with param coercion.

ikitommi15:07:32

sounds good, you should be able to build such a (data-driven) client with reitit. Just build on top of the core router + coercion.

ikitommi15:07:12

... and can use middleware or interceptors too in the client side, just like clj-http does

Casey15:07:22

yea, and the user will primarily use functions that call match-by-name

ikitommi15:07:38

if the legacy app already does swagger/openapi, you could use something like Martian (https://github.com/oliyh/martian).

ikitommi15:07:10

but definetely interesting, happy to help if you need anything.

ikitommi15:07:26

could be a example or module once finished?

Casey16:07:35

oh martian is interesting! thanks for that link. unfortunately this service doesn't have a swagger definition, but that would come in handy

Casey16:07:26

actually it looks like martian has a way to manually bootstrap it without swagger

ikitommi16:07:47

one reason for us tl start developing malli (https://github.com/metosin/malli) is to be able to serialize data model definitions over the wire: here, servers could expose all their route info to clients, which could mock those locally, generate uis etc

ikitommi16:07:24

Last time I checked, Martian used best-effort reverse engineering with schema for existing apis. Gives ok'ish results. The bootstrapping uses schema locally and is more sound.

Casey16:07:30

hm, yea i'd rather stick with spec as we already use it.

Casey16:07:44

will continue with the reitit experiment