Fork me on GitHub
#pedestal
<
2017-07-26
>
julianwegkamp14:07:05

@lxsameer You can implement a custom WebSocketListener to get the context in ws callback

lxsameer19:07:06

is it easy to use Pedestal router in a pure ring application ?

ddeaguiar19:07:11

@lxsameer Pedestal exposes a router through an interceptor, which has different properties as compared to a middleware fn. There are a number of router implementations in the Pedestal code base and they all implement the Router protocol (https://github.com/pedestal/pedestal/blob/master/route/src/io/pedestal/http/route/router.clj#L15). However, the router implementations have certain expectations. Firstly, they take a collection of expanded routes. Secondly, find-route is executed against a request map that has, at minimum, a :path-info and :request-method key. I don’t think :path-info is a standard ring request key.

ddeaguiar19:07:01

The result of find-route is the matched route. It’s the responsibility of the caller to then execute the interceptor chain associated with it.

ddeaguiar19:07:35

Pedestal’s router interceptor impl actually enqueues the interceptors from the matched route

ddeaguiar19:07:41

Given that, it may be possible to leverage a router implementation directly for it’s route matching capabilities

ddeaguiar19:07:39

What’s really required for route matching from the expanded route is the :path key

lxsameer19:07:53

Apparently I have to give up on Pedestal and use ring instead

ddeaguiar19:07:03

but you would still need to do some request map xform to create the add the :path-info key

ddeaguiar19:07:27

Here’s a snipped which captures the minimum requirements for route matching. I posted this sometime ago in response to a route testing inquiry https://gist.github.com/ddeaguiar/bed92b8f34b7e93f15cd0e5548d783ae#file-route_testing-clj-L30.

ddeaguiar19:07:38

I prefer Pedestal’s interceptor semantics over traditional middleware and found it fairly easy to port exiting middleware to interceptors

ddeaguiar19:07:25

I’ve also found that I’ve been able to use libraries in Pedestal that were built with ring in mind. Take Liberator as an example

ddeaguiar19:07:21

But I wouldn’t recommend mixing interceptors and middleware in an app because it would detract from the conceptual integrity of the system

lxsameer19:07:26

@ddeaguiar I think Pedestal is really cool, but there are several problems which really bother me

lxsameer19:07:04

for example websocket support is really awful at the moment, I ended up writing lots of enhancement to make it work as i want

lxsameer19:07:11

documentation is not good

ddeaguiar19:07:34

I definitely recommend raising them and it would be best to do so in the Pedestal user group as commentary there is durable

lxsameer19:07:35

But it's a really good choice to create a traditional web service

ddeaguiar19:07:10

Yes, documentation can definitely be improved and is something that I’ve been trying to help with. It’s just a bandwidth issue

ddeaguiar19:07:54

I’ve not done much with the websocket implementation to develop an opinion just yet.

ddeaguiar19:07:32

@lxsameer, out of curiosity, do you have a websocket implementation you prefer which you can provide for comparison purposes?

lxsameer19:07:16

@ddeaguiar Immutant and jetty supports websocket but to be honest those are just some implementation which are low level . But as a cool tool I suggest Sente which is more like a higher level tool and

lxsameer19:07:43

supports several backends like immutant , http-kit, aleph and several others

ddeaguiar19:07:57

I’ve heard of Sente. I’ll check it out, thanks