Middlewares

Middlewares are a collection of hooks that modify various processes of the gateway. All of them are passed into the gateway.WithMiddlewares Option:

gateway.New(..., gateway.WithMiddlewares(middleware1, middleware2))

At the moment the following middleware are provided:

Request Middleware

RequestMiddleware are called during execution when the gateway is sending a request to the backend service to look up the information that the client asked for.

addHeader := gateway.RequestMiddleware(func(r *http.Request) error {
	r.Header.Set("AwesomeHeader", "MyValue")

	// return the modified request
	return nil
})

Response Middleware

ResponseMiddleware are called during execution after a response has been generated before it is seralized and sent back to the user

logResponse := gateway.ResponseMiddleware(func(ctx *gateway.ExecutionContext, response map[string]interface{}) error {
	// you can also modify the response directly if you wanted
	fmt.Println(response)

	return nil
})