docs icon indicating copy to clipboard operation
docs copied to clipboard

πŸš€ Documentation improvement (BodyParser section):

Open smalloff opened this issue 3 years ago β€’ 4 comments

Hi! In the documentation, incomplete information about the request body parser. It took a long time to find a way to send arrays in parameters. I suggest adding an example to the documentation.

// curl -X POST -H "Content-Type: application/x-www-form-urlencoded" --data "users.0.name=john&users.1.name=jack" localhost:3000

type User struct {
    Name string `json:"name" xml:"name" form:"name"`
}

var users []User

app.Post("/", func(c *fiber.Ctx) error {
        if err := c.BodyParser(&users); err != nil {
            return err
        }

        log.Println(users[0].Name) // john
        log.Println(users[1].Name) // jack

        // ...
})

smalloff avatar Aug 16 '22 19:08 smalloff

users.0.name=john&users.1.name=jack looks strange, I think it must be like users[0][β€œname”]=john&users[1][β€œname”]=jack

ja3abuser avatar Aug 17 '22 09:08 ja3abuser

users.0.name=john&users.1.name=jack looks strange, I think it must be like users[0][β€œname”]=john&users[1][β€œname”]=jack

They're both supported

efectn avatar Aug 17 '22 09:08 efectn

users.0.name=john&users.1.name=jack looks strange, I think it must be like users[0][β€œname”]=john&users[1][β€œname”]=jack

this one can be added too. The fiber tests have several options.

smalloff avatar Aug 17 '22 11:08 smalloff

@smalloff can you create a pull request for this ?

ReneWerner87 avatar Aug 24 '22 09:08 ReneWerner87