pedestal

PK Anane 2024-04-23T10:50:49.977109Z

Hi guys.., I will be very grateful for your support. I have an issue where I cannot get the is_logged_in and id in my context I suspect its because of the # any pointers?

Phillip Mates 2024-04-23T10:53:38.606789Z

I recently came across something like this and noticed that # in a url is interpreted as a "URL fragment" and anything after it will be omitted from the query params part of the parsed URL.

👍 1
PK Anane 2024-04-23T10:54:49.058779Z

were you able to make any progress??

2024-04-23T10:55:51.827759Z

ChatGPT found it in the spec:

Phillip Mates 2024-04-23T10:56:04.300419Z

I just stopped using # in that place. For me it was that I was trying to put a set value in query params, so I had something like ?vals=#{1}&id=123 and changed it to use a vector instead of a set.

👍 1
PK Anane 2024-04-23T10:56:58.219019Z

makes sense.. suspected this as well..it;s HTTP standards

2024-04-23T10:57:03.259259Z

Or you could URL-encode it as %23

souenzzo 2024-04-23T12:33:15.805149Z

BROWSERS will not send the fragment, and it is a feature It allow client-only url's Some history-routing libraries API allow you to use if you want to use fragments or not https://google.github.io/closure-library/api/goog.history.Html5History.html HTTP says nothing about fragments. It is a URL thing You can send fragments to HTTP services using non-browser things, like curl or any other HTTP library (like clj-http) After a quick round of tests in pedestal, I see that the behavior is kind of undefined: • using io.pedestal.test/response-for, we get /hello#world in :path-info/:uri • using jetty, we get only /hello (the fragment is discarded by jetty)

hlship 2024-04-23T17:11:25.120789Z

Internally at Nubank, this has been perhaps the top request for Pedestal and strangely, it's never shown up in the issue list until I added it today. https://github.com/pedestal/pedestal/issues/842

adi 2024-05-12T17:11:59.865939Z

I'm trying out pedestal, and I notice as of version 0.7.0-beta-1, the default router cannot disambiguate the following routes, even though they have distinct and unique route names. My reading of pedestal's documentation suggests the unique route names should help the router disambiguate. Excerpt from the routing table printed to the REPL:

:get /item/new           :com.example/new-item-page
:get /item/:item-id/view :com.example/view-item-page
In this case, pedestal matches /item/:item-id/view but returns "not found" for /item/new. Whereas, if I change my "view" route to /item/view/:item-id, then both routes match and work as expected. Is this known and expected behaviour? If not, then I will tack this observation onto pedestal/issue/842.

2024-05-12T18:40:36.656489Z

This is a FAQ about Pedestal's built-in routing. See https://github.com/pedestal/pedestal/issues/842 which is currently Open. If you want to implement conflicting routes (which, in your hopes, will not conflict in practice for one reason or another) you may do so in your own interceptor.

souenzzo 2024-04-23T18:48:30.241079Z

so basically everyone agrees that it is a feature?! laughcry

isak 2024-04-23T19:01:13.442109Z

> Overlapping routes > Basically, I want to do this: >

(GET "/user/*" [] ...)
> (GET "/user/create" [] ...)
> Pedestal allows for map syntax (order-independence), but then forbids cases like this. Reitit makes those a special case that requires exceptional handling. > But I don’t think there’s anything is wrong with it or that it’s dangerous. It’s a pretty common case, really. Yes, you can’t create a user named "create", but so what? https://tonsky.me/blog/simple-router/ I agree with this post, I think pedestal just got this wrong.

hlship 2024-04-23T19:17:17.162229Z

Well, that does open you up to a "degenerate" case: how to you handle a user who'se is is literally create? Do you favor the wild-card over the static, or vice-versa?

hlship 2024-04-23T19:18:01.259869Z

At least in 0.7, you'll see all the routes at startup.

👍 2
isak 2024-04-23T19:20:07.400309Z

Static > wildcard. I think this makes sense, and from what I remember, this is how it works in web projects in other web libraries (maybe not Clojure).

isak 2024-04-23T19:21:43.711179Z

Yea from a quick web search this is what rails does - the wildcard is always the catch-all, last route to be checked.

2024-04-23T23:40:15.985989Z

Since Pedestal has interceptors, it has no need of catch-alls complecting the routers. A router that may process paths in any order could adaptively process the popular paths first.

2024-04-23T23:43:13.767289Z

Reserving some paths, but also using the wildcard, is a bit less principled than the usual "Clojure way". It could be called a hammock failure. It can be done, but it's a kluge and should look and smell like one.

adi 2024-05-15T12:35:44.315929Z

@phill I thought about your advice (thank you!), and figured writing good ol' non-conflicting routes is right and proper here. Among other things, I guess a custom interceptor will hide details from url-for, which would be a downer.