🤗 [Question]: How to use BodyParse in v3 ?
root9464 opened this issue · comments
iO commented
Question Description
package main
import (
"log"
"github.com/gofiber/fiber/v3"
"github.com/gofiber/fiber/v3/middleware/logger"
)
func main() {
app := fiber.New()
app.Use(logger.New())
app.Get("/", func(Ctx fiber.Ctx) error {
Ctx.BodyParser(struct{}{})
return Ctx.SendString("Hello, World!")
})
log.Fatal(app.Listen(":3000"))
}
Ctx.BodyParser undefined (type fiber.Ctx has no field or method BodyParser)compilerMissingFieldOrMethod
Code Snippet (optional)
package main
import "github.com/gofiber/fiber/v3"
import "log"
func main() {
app := fiber.New()
// An example to describe the question
log.Fatal(app.Listen(":3000"))
}
Checklist:
- I agree to follow Fiber's Code of Conduct.
- I have checked for existing issues that describe my questions prior to opening this one.
- I understand that improperly formatted questions may be closed without explanation.
welcome commented
Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord
Volker Lieber commented
It looks like it should be done via Ctx.Bind().Body
Source documentation:
Bind
: You can bind body, cookie, headers etc. into the map, map slice, struct easily by using Binding method. It gives custom binding support, detailed binding options and more. Replacement of: BodyParser, ParamsParser, GetReqHeaders, GetRespHeaders, AllParams, QueryParser, ReqHeaderParserBody
: Body binds the request body into the struct, map[string]string and map[string][]string. It supports decoding the following content types based on the Content-Type header: application/json, application/xml, application/x-www-form-urlencoded, multipart/form-data If none of the content types above are matched, it'll take a look custom binders by checking the MIMETypes() method of custom binder. If there're no custom binder for mşme type of body, it will return a ErrUnprocessableEntity error.
This change is currently not reflected in the official documentation
Juan Calderon-Perez commented
@VolkerLieber That's correct, the updates to the documentation are "Work In Progress".