Echo: Static route conflict with dynamic on same level

Created on 15 Aug 2016  路  7Comments  路  Source: labstack/echo

Hi,

I have two routes in group:

g.GET("/dictionary/skills", api.GetSkills)
g.GET("/dictionary/:name", api.GetDictionary)

When I call /dictionary/skills or /dictionary/type it work as expected, but when I call /dictionary/status router returns 404. I believe this is because matching work only on first letter for speed sake. When I remove /dictionary/skills route /dictionary/status work normal.

I think this is wrong behaviour, because I want to have common handler on all /dictionary/:name but for exception add only /dictionary/skills.

bug

Most helpful comment

Please check this exmaple. For me http://localhost:8001/g/dictionary/status return Not Found but http://localhost:8001/g/dictionary/type return type. If remove g.GET("/server", than status request work as expected.

e := echo.New()
g := e.Group("/g")
g.GET("/dictionary/skills", func(ctx echo.Context) error {
    return ctx.String(200, "skills")
})
g.GET("/dictionary/:name", func(ctx echo.Context) error {
    return ctx.String(200, ctx.Param("name"))
})
g.GET("/server", func(ctx echo.Context) error {
    return ctx.String(200, "server")
})

All 7 comments

I think it should be some behaviour due to your code. As example:

    e := echo.New()
    g := e.Group("/g")
    g.GET("/dictionary/skills", func(ctx echo.Context) error {
        return ctx.String(200, "skills")
    })
    g.GET("/dictionary/:name", func(ctx echo.Context) error {
        return ctx.String(200, ctx.Param("name"))
    })

Routers are working fine.

Yes your example work as expected! Thank you for it. I will try figure out source of problem and write later.

Please check this exmaple. For me http://localhost:8001/g/dictionary/status return Not Found but http://localhost:8001/g/dictionary/type return type. If remove g.GET("/server", than status request work as expected.

e := echo.New()
g := e.Group("/g")
g.GET("/dictionary/skills", func(ctx echo.Context) error {
    return ctx.String(200, "skills")
})
g.GET("/dictionary/:name", func(ctx echo.Context) error {
    return ctx.String(200, ctx.Param("name"))
})
g.GET("/server", func(ctx echo.Context) error {
    return ctx.String(200, "server")
})

Hi @vishr, do you have any thought about this error?

@sokolovstas I believe this issue is related to #675. I will work on it asap.

@sokolovstas please verify

Yes it working fine now! Many thanks for your efforts!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

syntaqx picture syntaqx  路  3Comments

linux-support picture linux-support  路  3Comments

mmindenhall picture mmindenhall  路  4Comments

montanaflynn picture montanaflynn  路  3Comments

toorop picture toorop  路  4Comments