#Fist 👊
1 messages · Page 1 of 1 (latest)
I wonder if the router could be inteospectable in some way
Perhaps for generating API documentation
It seems a bit odd to me there’s some functions for constructing responses, that seems unrelated to a router
You're right! I ended up merging everything I had together. Looking at it now, those functions don't really belong in the router. Since it was originally tightly coupled to Mist, I just brought them along as helper functions — and they ended up floating in the middle of everything. I'll probably move them to a separate module to keep things cleaner.
If it’s the same package having two modules makes it messier rather than neater
I think seeing as they’re not related it routing they would be best moved from the routing library into either your application or into another that is focused on responses in some fashion
For example, if you were to make a whole web framework
Though we do have a few of those already
NOTED!!
I believe so, since the router is internally a Dict(Method, Node), I think it would be possible to write a function that walks the tree and reconstructs the paths. The only tricky part would be the dynamic segments like :id — they already gave me some trouble when figuring out how they should work in the first place, so reconstructing them from the tree might be a bit of a challenge.
I wonder what information could be attached to the routes
hmm
like a optional label or docstring ?
If, for example, we follow the pipeline example, I believe it could be something like:
fist.new()
|> fist.get("/users/:id", to: handler)
|> fist.describe("Returns a user by ID")
describe, which simply places a documentation string on the last registered route.
Oh that’s a cool DSL
Perhaps you could even try to make a DSL that instead of using string paths has type safe path parens by using a builder function to describe the path
Though won’t look like Axum
I was actually quite against using string paths when we were making Axum, but most the team wanted it to look more like express JS
I spent a while thinking about how to do this, considered creating a whole parallel structure, a bunch of extra fields, etc. Then I realized I already had everything I needed in the Node, I just needed to walk the tree and collect the paths. Felt like a genius and an idiot at the same time.
the OO is in my vains
let router =
fist.new()
|> fist.get("/api/v1/users", to: h)
|> fist.describe("V1 Users")
|> fist.get("/api/v1/posts/:postId/comments", to: h)
|> fist.describe("Comments")
let routes = fist.inspect(router)