#Fist 👊

1 messages · Page 1 of 1 (latest)

sleek glacier
#

Looks cool!

#

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

frigid shard
sleek glacier
#

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

frigid shard
#

NOTED!!

frigid shard
# sleek glacier Perhaps for generating API documentation

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.

sleek glacier
#

I wonder what information could be attached to the routes

frigid shard
#

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.

sleek glacier
#

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

frigid shard
#

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)