Skip to main content
InterviewHubPRO
Section Overview
Q29

Question 29 of 50

Part 3: Go Microservices, HTTP, gRPC & Architecture (33 - 44)

58%
Golang & Concurrency (50 Qs)•Part 3: Go Microservices, HTTP, gRPC & Architecture (33 - 44)

How does HTTP Routing work in Go 1.22 (`http.NewServeMux`) with Method Matching and Wildcards?

senior LevelCode ExampleRoutingSystem DesigngRPC

In Simple Words: In Go 1.22, the standard library http.ServeMux added native method routing and URL pattern matching without needing external frameworks:

go
mux := http.NewServeMux()

// Method matching and path parameter wildcards
mux.HandleFunc("GET /users/{id}", func(w http.ResponseWriter, r *http.Request) {
	userId := r.PathValue("id")
	fmt.Fprintf(w, "User ID: %s", userId)
})

mux.HandleFunc("POST /users", createUserHandler)