I run a helloworld gin in my localhost,code as follow:
package main
import "github.com/gin-gonic/gin"
func main() {
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
r.Run() // listen and serve on 0.0.0.0:8080
}
Then I do some http request by curl like follow:
>> curl http://localhost:8080/ping
{"message":"pong"}%
>> curl -d "" http://localhost:8080/ping
404 page not found%
The second request shall be 405 ref by http status code 405 rather than 404.
Any plan for support more proper http status code, or I misunderstand something?
you should set r.HandleMethodNotAllowed = true
@thinkerou thanks! solved my problem
Most helpful comment
you should set
r.HandleMethodNotAllowed = true