Skip to content

Commit ca2aadd

Browse files
Add docs from gofiber/fiber@cd273d2
1 parent d21f1bb commit ca2aadd

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

docs/core/api/app.md

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,14 @@ func handler(c fiber.Ctx) error {
138138
}
139139
```
140140

141-
### Route
141+
### RouteChain
142142

143143
Returns an instance of a single route, which you can then use to handle HTTP verbs with optional middleware.
144144

145-
Similar to [`Express`](https://expressjs.com/de/api.html#app.route).
145+
Similar to [`Express`](https://expressjs.com/en/api.html#app.route).
146146

147147
```go title="Signature"
148-
func (app *App) Route(path string) Register
148+
func (app *App) RouteChain(path string) Register
149149
```
150150

151151
<details>
@@ -166,7 +166,7 @@ type Register interface {
166166

167167
Add(methods []string, handler Handler, handlers ...Handler) Register
168168

169-
Route(path string) Register
169+
RouteChain(path string) Register
170170
}
171171
```
172172

@@ -184,12 +184,12 @@ import (
184184
func main() {
185185
app := fiber.New()
186186

187-
// Use `Route` as a chainable route declaration method
188-
app.Route("/test").Get(func(c fiber.Ctx) error {
187+
// Use `RouteChain` as a chainable route declaration method
188+
app.RouteChain("/test").Get(func(c fiber.Ctx) error {
189189
return c.SendString("GET /test")
190190
})
191191

192-
app.Route("/events").All(func(c fiber.Ctx) error {
192+
app.RouteChain("/events").All(func(c fiber.Ctx) error {
193193
// Runs for all HTTP verbs first
194194
// Think of it as route-specific middleware!
195195
}).
@@ -202,12 +202,12 @@ func main() {
202202
})
203203

204204
// Combine multiple routes
205-
app.Route("/v2").Route("/user").Get(func(c fiber.Ctx) error {
206-
return c.SendString("GET /v2/user")
205+
app.RouteChain("/reports").RouteChain("/daily").Get(func(c fiber.Ctx) error {
206+
return c.SendString("GET /reports/daily")
207207
})
208208

209209
// Use multiple methods
210-
app.Route("/api").Get(func(c fiber.Ctx) error {
210+
app.RouteChain("/api").Get(func(c fiber.Ctx) error {
211211
return c.SendString("GET /api")
212212
}).Post(func(c fiber.Ctx) error {
213213
return c.SendString("POST /api")
@@ -217,6 +217,21 @@ func main() {
217217
}
218218
```
219219

220+
### Route
221+
222+
Defines routes with a common prefix inside the supplied function. Internally it uses [`Group`](#group) to create a sub-router and accepts an optional name prefix.
223+
224+
```go title="Signature"
225+
func (app *App) Route(prefix string, fn func(router Router), name ...string) Router
226+
```
227+
228+
```go title="Example"
229+
app.Route("/test", func(api fiber.Router) {
230+
api.Get("/foo", handler).Name("foo") // /test/foo (name: test.foo)
231+
api.Get("/bar", handler).Name("bar") // /test/bar (name: test.bar)
232+
}, "test.")
233+
```
234+
220235
### HandlersCount
221236

222237
Returns the number of registered handlers.

docs/core/whats_new.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -328,18 +328,17 @@ In `v2` one handler was already mandatory when the route has been registered, bu
328328

329329
### Route chaining
330330

331-
The route method is now like [`Express`](https://expressjs.com/de/api.html#app.route) which gives you the option of a different notation and allows you to concatenate the route declaration.
331+
This release introduces a dedicated `RouteChain` helper, inspired by [`Express`](https://expressjs.com/en/api.html#app.route), for declaring a stack of handlers on the same path. The original `Route` helper for prefix encapsulation also remains available.
332332

333-
```diff
334-
- Route(prefix string, fn func(router Router), name ...string) Router
335-
+ Route(path string) Register
333+
```go
334+
RouteChain(path string) Register
336335
```
337336

338337
<details>
339338
<summary>Example</summary>
340339

341340
```go
342-
app.Route("/api").Route("/user/:id?")
341+
app.RouteChain("/api").RouteChain("/user/:id?")
343342
.Get(func(c fiber.Ctx) error {
344343
// Get user
345344
return c.JSON(fiber.Map{"message": "Get user", "id": c.Params("id")})
@@ -360,11 +359,11 @@ app.Route("/api").Route("/user/:id?")
360359

361360
</details>
362361

363-
You can find more information about `app.Route` in the [API documentation](./api/app#route).
362+
You can find more information about `app.RouteChain` and `app.Route` in the API documentation ([RouteChain](./api/app#routechain), [Route](./api/app#route)).
364363

365364
### Middleware registration
366365

367-
We have aligned our method for middlewares closer to [`Express`](https://expressjs.com/de/api.html#app.use) and now also support the [`Use`](./api/app#use) of multiple prefixes.
366+
We have aligned our method for middlewares closer to [`Express`](https://expressjs.com/en/api.html#app.use) and now also support the [`Use`](./api/app#use) of multiple prefixes.
368367

369368
Prefix matching is now stricter: partial matches must end at a slash boundary (or be an exact match). This keeps `/api` middleware from running on `/apiv1` while still allowing `/api/:version` style patterns that leverage route parameters, optional segments, or wildcards.
370369

@@ -1653,7 +1652,7 @@ app.Add([]string{fiber.MethodPost}, "/api", myHandler)
16531652

16541653
#### Mounting
16551654

1656-
In Fiber v3, the `Mount` method has been removed. Instead, you can use the `Use` method to achieve similar functionality.
1655+
In this release, the `Mount` method has been removed. Instead, you can use the `Use` method to achieve similar functionality.
16571656

16581657
```go
16591658
// Before
@@ -1667,7 +1666,7 @@ app.Use("/api", apiApp)
16671666

16681667
#### Route Chaining
16691668

1670-
Refer to the [route chaining](#route-chaining) section for details on migrating `Route`.
1669+
Refer to the [route chaining](#route-chaining) section for details on the new `RouteChain` helper. The `Route` function now matches its v2 behavior for prefix encapsulation.
16711670

16721671
```go
16731672
// Before
@@ -1687,7 +1686,7 @@ app.Route("/api", func(apiGrp Router) {
16871686

16881687
```go
16891688
// After
1690-
app.Route("/api").Route("/user/:id?")
1689+
app.RouteChain("/api").RouteChain("/user/:id?")
16911690
.Get(func(c fiber.Ctx) error {
16921691
// Get user
16931692
return c.JSON(fiber.Map{"message": "Get user", "id": c.Params("id")})

0 commit comments

Comments
 (0)