Module 06 Β· HTTP with net/http β Lesson 3 of 3 Β· ~9 min
Routing (Go 1.22 mux)
One handler isn't a server
A real API has many endpoints: GET /walkers to list, GET /walkers/{id} for one walker, POST /bookings to book. You need something that looks at each request's method and path and dispatches to the right handler. That router is called a mux (multiplexer), and Go has one built in: http.ServeMux.
You've been using the default mux implicitly β passing nil to ListenAndServe and calling the package-level http.HandleFunc. Now you'll create your own so routing is explicit and testable.