Skip to content

🚀 [Feature]: Allow rebuilding route tree stack #2769

@rebaz94

Description

@rebaz94

Feature Description

I was thinking it'd be awesome if the buildTree method in App could be made public. This tweak would open up possibilities for dynamic request handling.

already checked #735 I get that rebuilding the tree might be resource-intensive, but we'd only use it during development. This way, we can ensure our routing behaves as expected without resorting to an * route and redoing all the routing and parsing logic.

Our goal is to enable users to define routes dynamically, with handlers loaded in on-the-fly. So, by simply making the buildTree method public, it'd really help us out.

Additional Context (optional)

The code snippet below illustrates how making buildTree public could streamline fiber routing without the need for using *.

s.app.Get("/define", func(ctx *fiber.Ctx) error {
		// load config
		path := "/test/:param"
		s.app.Get(path, func(ctx *fiber.Ctx) error {
			// load the handler instruction
			// executing logic written by user
			// can access the :param easily
			return nil
		})
		// after each definition
		s.app.BuildTree()

		return ctx.JSON(map[string]any{
			"success": true,
		})
	})

Code Snippet (optional)

No response

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my suggestion prior to opening this one.
  • I understand that improperly formatted feature requests may be closed without explanation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions