Handle unknown HTTP method

Currently all requests are routed to our books handler. We add a check for the GET method and fail accordingly.
func (h *books) ServeHTTP(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + w.WriteHeader(http.StatusMethodNotAllowed) + return + } w.Header().Set("Content-Type", "application/json") model := struct { Message string `json:"message"`
prev toc next