From e561026384944dadf18b316a74ec658735317ca9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9?= Date: Fri, 7 Jun 2024 17:01:07 +0200 Subject: [PATCH] [v3 Maintenance]: Consolidate and Document Core Changes in v3 --- docs/whats_new.md | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/docs/whats_new.md b/docs/whats_new.md index ff8b834d46..bf7c00f39a 100644 --- a/docs/whats_new.md +++ b/docs/whats_new.md @@ -325,6 +325,51 @@ You have to put `*` to the end of the route if you don't define static route wit ### 🗺 Router +The signatures for [`Add`](#middleware-registration) and [`Route`](#route-chaining) have been changed. + +To migrate [`Add`](#middleware-registration) you must change the `methods` in a slice. + +```go +// Before +app.Add(fiber.MethodPost, "/api", myHandler) +``` + +```go +// After +app.Add([]string{fiber.MethodPost}, "/api", myHandler) +``` + +To migrate [`Route`](#route-chaining) you need to read [this](#route-chaining). + +```go +// Before +app.Route("/api", func(apiGrp Router) { + apiGrp.Route("/user/:id?", func(userGrp Router) { + userGrp.Get("/", func(c fiber.Ctx) error { + // Get user + return c.JSON(fiber.Map{"message": "Get user", "id": c.Params("id")}) + }) + userGrp.Post("/", func(c fiber.Ctx) error { + // Create user + return c.JSON(fiber.Map{"message": "User created"}) + }) + }) +}) +``` + +```go +// After +app.Route("/api").Route("/user/:id?") + .Get(func(c fiber.Ctx) error { + // Get user + return c.JSON(fiber.Map{"message": "Get user", "id": c.Params("id")}) + }) + .Post(func(c fiber.Ctx) error { + // Create user + return c.JSON(fiber.Map{"message": "User created"}) + }); +``` + ### 🧠 Context ### 📎 Parser @@ -387,4 +432,4 @@ app.Use(static.New("", static.Config{ IndexNames: []string{"index.html"}, MaxAge: 3600, })) -``` \ No newline at end of file +```