Skip to content

Unable to bind url params #1337

@abaird1992

Description

@abaird1992

/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
/ / / / / / / / / / / / / / / / / /

Please use forum https://forum.labstack.com to ask questions!

/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
/ / / / / / / / / / / / / / / / / /

Issue Description

When I use the Context#Bind method of the Context#DefaultBinder (default implementation for the Context#Binder interface), I cannot bind the parameters contained in the url/path of the request.

Checklist

  • Dependencies installed
  • No typos
  • Searched existing issues and docs

Expected behavior

Code for the handler (derived from the examples in the documentation):

e.GET("/users/:name", func(c echo.Context) error {
  u := new(User)
  if err = c.Bind(u); err != nil {
    return
  }
  return c.JSON(http.StatusOK, u)
})

Code defining user type, also taken from the examples in the documentation

// User
type User struct {
  Name  string `json:"name" form:"name" url:"name"`
  Email string `json:"email" form:"email" query:"email"`
}

If I run the following request:

curl -XGET http://localhost:1323/users/Joe\?email\=joe_email

I would expect the Name field in u to be equal to "Joe".

Actual behavior

When executing the following request:

curl -XGET http://localhost:1323/users/Joe\?email\=joe_email

The Name field in u remains empty.

Steps to reproduce

Working code to debug

Version/commit

v4.1.5

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions