I know context.JSON() returns the serialised object with content type "application/json; charset=utf-8". But I want to skip serialising by returning cached plain text, because my object does not change constantly.
Is it possible to use something like context.String() but set content type "application/json; charset=utf-8"?
Thanks.
Check out context.Header(). You should be able to do this:
context.Header("Content-Type", "application/json; charset=utf-8")
context.String(...)
@mattprice Thanks for the reply. But it does not work because context.String() overwrites Content-Type.
Odd. What about context.Data()?
context.Data(200, "application/json; charset=utf-8", []byte(someString))
It looks promising. I will try. Thanks.
@mattprice It works. Thanks!
Most helpful comment
Odd. What about
context.Data()?