gojek / heimdall

An enhanced HTTP client for Go
http://gojek.tech
Apache License 2.0
2.63k stars 214 forks source link

[Enhancement] Get Response Body Directly #68

Open imjuanleonard opened 5 years ago

imjuanleonard commented 5 years ago

Usecase: After using the HTTP client to Do the request. We want to directly unmarshal the response body into a certain struct. If it fails, we just want to know the status code of the API and returns accordingly.

The snippet of working code will be like:

responseBody := YourProgramResponseBodyStruct{}
httpStatusCode, err := heimdall.ResponseBody(req, &responseBody)

What good it will do: It reduces the need to write again and again for decoding the response body. Saving lines of code with this abstraction