Closed Snax1210 closed 3 weeks ago
I do not understand about
into a single method
But if you're asking whether it can be used together in the request chain, then yes, you can.
Example:
client := resty.New()
resp, err = client.R().
SetBody(user).
SetResult(&AuthSuccess{}).
ForceContentType("application/json").
Post("https://example.com/login")
fmt.Println(err, resp)
In other words, could we add ForceContentType("application/json") to SetResult(&AuthSuccess{}) so that you don't have to consider the type of response header when mapping to structs
When you set the ForceContentType("application/json"),
, then Resty uses this content type value when Unmarshalling the response body, not the response header value.
The original intention of using SetResult() is to convert the response into a struct, but sometimes the response header is not "application/json", and you need to add ForceContentType(" application/json") separately