yarf icon indicating copy to clipboard operation
yarf copied to clipboard

url with tailling flash /hello/aa/ match route "/hello/:name" should return 404 like net/http

Open tablecell opened this issue 3 years ago • 1 comments

package main

import "github.com/yarf-framework/yarf"

type Hello struct {
	yarf.Resource
}

func (h *Hello) Get(c *yarf.Context) error {
	name := c.Param("name")

	c.Render("Hello, " + name)

	return nil
}
func main() {
	// Create a new empty YARF server
	y := yarf.New()
	hello := new(Hello)
	y.Add("/", hello)
	y.Add("/hello/:name", hello)
	y.Start(":8080")
}

$ curl http://localhost:8080/hello/xxx/ Hello, xxx

package main
import (
    "fmt"
    "net/http"
)
func main() {
    http.HandleFunc("/hello/xxx", func (w http.ResponseWriter, r *http.Request) {
        fmt.Fprintf(w, "Welcome to my website!")
    })
   http.ListenAndServe(":80", nil)
}

curl http://localhost:8080/hello/xxx/ Not found

tablecell avatar Sep 03 '21 00:09 tablecell

Hi @tablecell ,

The trailing slash behaviour is made on purpose here. As described in the README doc in the "Simple router" section. The implementation code is also clear about that purpose.

That said, other than what net/http does, is there other arguments to discuss about this? I'm open to review the design.

leonelquinteros avatar Sep 03 '21 13:09 leonelquinteros