Files
greenlight/cmd/api/routes.go
Maxime Delporte b76496e096
All checks were successful
Deploy Greenlight API / deploy (push) Successful in 1m20s
Updating updateMovieHandler to be able to update only some fields (patch instead of put). Update routes with the correct verb.
2025-11-07 11:57:04 +01:00

34 lines
1.4 KiB
Go

package main
import (
"github.com/julienschmidt/httprouter"
"net/http"
)
func (app *application) routes() http.Handler {
// Initialize a new httprouter router instance
router := httprouter.New()
// Convert the notFoundResponse() helper to a http.Handler using the http.HandlerFunc() adapter, and then set it as the custom error handler for 404 Not Found responses.
router.NotFound = http.HandlerFunc(app.notFoundResponse)
// Likewise, convert the methodNotAllowedResponse() helper to a http.Handler and set it as the custom error handler for 405 Method Not Allowed responses
router.MethodNotAllowed = http.HandlerFunc(app.methodNotAllowedResponse)
/*
Register the relevant methods, URL patterns and handler functions for our
endpoints using the HandlerFunc() method. Note that http.MethodGet and
http.MethodPost are constants which equate to the strings "GET" and "POST"
respectively.
*/
router.HandlerFunc(http.MethodGet, "/v1/healthcheck", app.healthcheckHandler)
router.HandlerFunc(http.MethodPost, "/v1/movies", app.createMovieHandler)
router.HandlerFunc(http.MethodGet, "/v1/movies/:id", app.showMovieHandler)
router.HandlerFunc(http.MethodPatch, "/v1/movies/:id", app.updateMovieHandler)
router.HandlerFunc(http.MethodDelete, "/v1/movies/:id", app.deleteMovieHandler)
// Return the httprouter instance.
// Wrap the router with the panic recovery middleware
return app.recoverPanic(router)
}