Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚀 v3 Request: New ideas for routing and mounting #1829

Open
balcieren opened this issue Mar 21, 2022 · 6 comments
Open

🚀 v3 Request: New ideas for routing and mounting #1829

balcieren opened this issue Mar 21, 2022 · 6 comments
Assignees
Milestone

Comments

@balcieren
Copy link
Contributor

balcieren commented Mar 21, 2022

New Router instead of Group , Route and Mount (should be deprecate)

Express Router

Routing

func UserRouter() *fiber.Router {
	router := fiber.NewRouter()

	router.Get("/", func(c *fiber.Ctx) error {
		return c.JSON("fiber v3")
	})

	return router
}

func main() {
	app := fiber.New()

	app.Use("/user", UserRouter)

	app.Listen(":3000")
}

RouterConfig can contain

router-config


Mounting (#2022)

Express Mount

func main() {
	app := fiber.New()

	user := fiber.New()

	user.Get("/", func(c *fiber.Ctx) error {
		return c.JSON("fiber-v3")
	})

	user.On("mount", func(parent *fiber.App) {
		fmt.Println("user mounted")
	})

	app.Use("/user", user)

	app.Listen(":3000")
}

fiber.Route() (#2065)

Express Route

func main() {
	app := fiber.New()

	app.Route("/events").
		All(func(c *fiber.Ctx) error {
			...
		}).
		Get(func(c *fiber.Ctx) error {
			...
		}).
		Post(func(c *fiber.Ctx) error {
			...
		})

	app.Listen(":3000")
}
@ReneWerner87 ReneWerner87 added this to the v3 milestone Mar 21, 2022
@efectn efectn added this to v3 Jun 5, 2022
@efectn efectn moved this to Todo in v3 Jun 5, 2022
@efectn efectn removed this from v3 Jun 5, 2022
@efectn efectn added this to v3 Jun 5, 2022
@efectn efectn moved this to Todo in v3 Jun 5, 2022
@vishjain
Copy link

vishjain commented Jul 8, 2022

@ReneWerner87 Can I work on this feature?

@efectn
Copy link
Member

efectn commented Jul 8, 2022

@ReneWerner87 Can I work on this feature?

You can work for this feature. Also i have some ideas about mounting and grouping after this feature. If you open a PR, i can add some comments

@efectn
Copy link
Member

efectn commented Aug 2, 2022

Hi @vishjain. Are there any progress?

@vishjain
Copy link

vishjain commented Aug 2, 2022

Working on it right now. Thanks!

@m13t
Copy link

m13t commented Aug 31, 2022

I'm quite keen to see if this would support my use case as I was surprised it doesn't work in v2. I'm essentially dynamically constructing an additional router in a piece of middleware and then handing off to that router. This is something I've done similar in express for complex dynamic multi-tenanted apps but short of creating it all in a fiber.Handler and branching that in the middleware I'm not sure how else to do it. Would be nice to see this in v3.

To clarify I'm not talking about utilising app.Use or app.Mount here as that is adding to the middleware stack for the app instance, not per request. Essentially it's a router or app instance lacking the ability to be called by another app like a Handler can be.

e.g.

func createSubRouter() *fiber.Router {
  r := fiber.New()
  r.Get("/", func(c *fiber.Ctx) error {
    c.JSON("Dynamic Route")
  })
  return r
}

func main() {
  app := fiber.New()
  app.Use(func(c *fiber.Ctx) error {
    if someCondition() {
      r := createSubRouter()
      return r.Handle(c)
    }

    // Standard flow
    return c.Next()
  }
}

@efectn
Copy link
Member

efectn commented Nov 4, 2022

I'm going to start implementing router in the next weeks 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

5 participants