Skip to content

Commit a623953

Browse files
Add docs from gofiber/fiber@9ea7651
1 parent 78f0b01 commit a623953

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

docs/core/api/app.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,3 +573,31 @@ Hooks is a method to return [hooks](./hooks.md) property.
573573
```go title="Signature"
574574
func (app *App) Hooks() *Hooks
575575
```
576+
577+
## RebuildTree
578+
579+
The RebuildTree method is designed to rebuild the route tree and enable dynamic route registration. It returns a pointer to the App instance.
580+
581+
```go title="Signature"
582+
func (app *App) RebuildTree() *App
583+
```
584+
585+
**Note:** Use this method with caution. It is **not** thread-safe and calling it can be very performance-intensive, so it should be used sparingly and only in development mode. Avoid using it concurrently.
586+
587+
### Example Usage
588+
589+
Here’s an example of how to define and register routes dynamically:
590+
591+
```go
592+
app.Get("/define", func(c Ctx) error { // Define a new route dynamically
593+
app.Get("/dynamically-defined", func(c Ctx) error { // Adding a dynamically defined route
594+
return c.SendStatus(http.StatusOK)
595+
})
596+
597+
app.RebuildTree() // Rebuild the route tree to register the new route
598+
599+
return c.SendStatus(http.StatusOK)
600+
})
601+
```
602+
603+
In this example, a new route is defined and then `RebuildTree()` is called to make sure the new route is registered and available.

docs/core/whats_new.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,31 @@ app.Route("/api").Route("/user/:id?")
437437
});
438438
```
439439

440+
### 🗺 RebuildTree
441+
442+
We have added a new method that allows the route tree stack to be rebuilt in runtime, with it, you can add a route while your application is running and rebuild the route tree stack to make it registered and available for calls.
443+
444+
You can find more reference on it in the [app](./api/app.md#rebuildtree):
445+
446+
#### Example Usage
447+
448+
```go
449+
app.Get("/define", func(c Ctx) error { // Define a new route dynamically
450+
app.Get("/dynamically-defined", func(c Ctx) error { // Adding a dynamically defined route
451+
return c.SendStatus(http.StatusOK)
452+
})
453+
454+
app.RebuildTree() // Rebuild the route tree to register the new route
455+
456+
return c.SendStatus(http.StatusOK)
457+
})
458+
```
459+
460+
In this example, a new route is defined and then `RebuildTree()` is called to make sure the new route is registered and available.
461+
462+
**Note:** Use this method with caution. It is **not** thread-safe and calling it can be very performance-intensive, so it should be used sparingly and only in
463+
development mode. Avoid using it concurrently.
464+
440465
### 🧠 Context
441466

442467
### 📎 Parser

0 commit comments

Comments
 (0)