Skip to content

🤗 Is possible to Add or Remove an route on-the-fly? #735

@mirusky

Description

@mirusky

Question description

I'm trying to create a dynamic router where user pass the httpMethod, router and handler ( prevealy defined ). So user will make a request

POST /route
{
"method": "POST",
"handler": "Ping",
"path": "/ping"
}

and a new /ping route will be added.

if user wants to change the route he do:

PUT /route
{
"method": "GET",
"handler": "Ping",
"path": "/ping"
}

or delete the route:

DELETE /route
{
"method": "POST",
"handler": "Ping",
"path": "/ping"
}

Code snippet
I've tried the following:

package main

import "github.com/gofiber/fiber"

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

	app.Get("/add", func(c *fiber.Ctx) {
		app.Get("/ping", Ping)
		m := make(map[string]string)
		m["message"] = "Ping Added!"
		c.JSON(m)
	})

	app.Listen("8080")
}

// Ping return a Pong message
func Ping(c *fiber.Ctx) {
	m := make(map[string]string)
	m["message"] = "Pong!"
	c.JSON(m)
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions