-
Reading the documentation for v4, https://echo.labstack.com/guide/binding/ gave me the impression that I can define a struct type GetPDF struct {
ID string `param:"id" validate:"required,uuid4"`
} and then bind it. Given the route #1337 says that binding to path parameters is a v5 feature, but #2333 indicates otherwise. I am using v4.10.2. What am I doing wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
I am trying path params binding this way - and it seems to work. func main() {
e := echo.New()
e.Use(middleware.Logger())
e.GET("/pdf/:id", func(c echo.Context) error {
type GetPDF struct {
ID string `param:"id" validate:"required,uuid4"`
}
var payload GetPDF
if err := c.Bind(&payload); err != nil {
return c.String(http.StatusBadRequest, "bad request")
}
return c.JSON(http.StatusOK, payload)
})
if err := e.Start(":8080"); err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatal(err)
}
} Output from command line: x@x:~/code$ curl http://localhost:8080/pdf/cfb8d234-ab46-412d-93ad-a2a7eab1f6f6
{"ID":"cfb8d234-ab46-412d-93ad-a2a7eab1f6f6"} Output from server:
|
Beta Was this translation helpful? Give feedback.
@smares , you function would work like this
and call it as
and full example: