Chi Router

I've used chi as a lightweight router for building HTTP services.

Middleware

Middleware is configured between defining a new chi.NewRouter() and calling ListenAndServe()

Full list of chi built-in middlewares

The iOS api uses:

Also looking into HttpRate for rate limiting.

Writing your own middleware

Middleware is a function that receives an http.Handler and returns an http.Handler.

A Handler responds to an HTTP request.

func (s *Server) metricsMiddleware(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		// Do some stuff here...

		

next.ServeHTTP(w, r)
	})
}

Inside your custom handler you can do things like read the body.