You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -48,3 +48,60 @@ err := request.Post("http://example.com", Input{RequestValue: "someValueIn"}, re
48
48
## Streaming
49
49
The package allows the request body (`Body` property of `Params`) to be of type `io.Reader`. That way you can pass on request bodies to other services without parsing them.
50
50
51
+
## Why?
52
+
To understand why this package was created have a look at the code that would be the native equivalent of the code shown in the example above.
CheckRedirect: func(req *http.Request, via []*http.Request) error {
92
+
return http.ErrUseLastResponse
93
+
},
94
+
}
95
+
96
+
res, err:= client.Do(req)
97
+
if err != nil {
98
+
return err
99
+
}
100
+
deferfunc() {
101
+
res.Body.Close()
102
+
}()
103
+
104
+
result:= &Output{}
105
+
err = json.NewDecoder(res.Body).Decode(result)
106
+
```
107
+
This shows the request package saves a lot of boilerplate code. instead of around 35 lines we just write the 9 lines shown in the example. That way the code is much easier to read and maintain.
0 commit comments