Mux.jl icon indicating copy to clipboard operation
Mux.jl copied to clipboard

page doesn't work without todict

Open christopher-dG opened this issue 5 years ago • 3 comments

https://github.com/JuliaWeb/Mux.jl/blob/master/src/routing.jl#L42

page(p::Vector, app...) = 
  branch(req -> length(p) == length(req[:path]) && matchpath!(p, req), app...)

req[:app] makes the assumption that the request is a Dict with that key, which is only the case when todict has been used.

christopher-dG avatar Apr 12 '19 20:04 christopher-dG

I wonder if it might make sense to just make todict a built-in middleware, and if necessary just make the original Requst object a field in the resulting dictionary. @christopher-dG do you have a use-case that requires using the HTTP Request object directly?

jpsamaroo avatar Apr 21 '19 19:04 jpsamaroo

I was looking for the simplest path from an HTTP app to a Mux one, so I didn't want to change my handlers. I like working with structs over dicts, it's just preference really.

christopher-dG avatar Apr 21 '19 19:04 christopher-dG

Given that pretty much all the provided middleware uses the assumed dictionary, it might be a decent chunk of work to add methods for using the Request object directly. There's also the question of, what do you use to pass state around between middleware. Any ideas?

jpsamaroo avatar Apr 21 '19 19:04 jpsamaroo