Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GoLang Gin Framework Status Code Without Message Body

Tags:

go

go-gin

I'm using GoLang and Gin Framework.

I need to respond for REST API call with 204 response code without message body.

How it is to do properly?

What I could find by digging the source code

c.JSON(204, "")

But server throws error at such case:

Error #01: http: request method or response status code does not allow body Meta: []

Any ideas?

like image 200
Bogdan Nechyporenko Avatar asked Feb 16 '26 20:02

Bogdan Nechyporenko


1 Answers

adding on @depado comments,

c.Status(http.StatusNoContent) is the simplest way to achieve this. Works with gin v1.6.3

like image 166
Sathish Avatar answered Feb 18 '26 22:02

Sathish



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!