Gin: Http Status Code 405 Not Supported Properly

Created on 8 Nov 2018  路  2Comments  路  Source: gin-gonic/gin

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?

question

Most helpful comment

you should set r.HandleMethodNotAllowed = true

All 2 comments

you should set r.HandleMethodNotAllowed = true

@thinkerou thanks! solved my problem

Was this page helpful?
0 / 5 - 0 ratings