How do I serve text/html #530
Replies: 2 comments 1 reply
-
You probably shouldn't return plain HTML at all, but you can always set the Body to type GreetingOutput struct {
ContentType string `header:"Content-Type"`
Body []byte `example:"<h1>Hello, world!</h1>" doc:"Greeting message"`
} Then return the HTML as follows: resp := &GreetingOutput{}
resp.Body = []byte(fmt.Sprintf("<h1>Hello, %s!</h1>", input.Name))
resp.ContentType = "text/html"
return resp, nil |
Beta Was this translation helpful? Give feedback.
-
First off, thank you for the work you've done; I'm just playing around with it and seems quite useful. FWIW I think there are legit reasons to return pre-rendered HTML content even through an API. My current website does HTMX-style server-side rendering of individual components of the page, which the front-end JS will request and then shove into page elements. I managed to come up with the solution @baderj suggested, and came here to see if there was anything better. It's OK, but it would be nicer if (e.g.) I could set |
Beta Was this translation helpful? Give feedback.
-
Hello Daniel,
we have recently adopted huma at my current employer, and have had great success with a data api we have built.
I am trying to expand my understanding of how to use this framework, but I can't figure out how to get it to serve good old html content.
for example I have modified the greetings example to return basic html.
I expected this to work.
But I get
I have tried to figure it out on my own and I am stuck please help.
Beta Was this translation helpful? Give feedback.
All reactions