Skip to content

How can one define the headers once for all endpoints? #658

Answered by artisanphil
artisanphil asked this question in Q&A
Discussion options

You must be logged in to vote

@danielgtaylor Thank you.

I got it working like this:

        api.UseMiddleware(func(ctx huma.Context, next func(huma.Context)) {
		ctx.SetHeader("Cache-Control", "max-age=86400")
		next(ctx)
	})

For the documentation itself, I'm now just describing the headers on the overview page rather than per endpoint (e.g. under config.Info.Description).

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@artisanphil
Comment options

Answer selected by artisanphil
@danielgtaylor
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants