go-restclient v0.1.0
v0.1.0
As this is the first release of go-restclient
, its feature set pretty much contains everything that are intended as default for go-restclient
implementation, which are in general:
With restclient.NewRequest(...)
- Constructing URL by escaping path components
- Marshaling RequestBody if exists
- Building the request object
- Validating that resulting URI is valid
- Setting queryParams if exists
- Setting custom headers
After calling client.Get(...)
on client := restclient.NewHttpClient()
- Setting universal headers
- Setting Authorization header by applying specified authenticator's strategy
- Setting context timeout and defer its cancellation
- Doing Request (Timing and Logging it if needed)
- Handling Response Status Code
- Reading the body and unmarshal it into given value
Wrappers
There also exists wrappers for usage convenience which converts below code piece:
ri := NewRequestInfo(scheme, host, ...) // or NewRequestInfoFromRawURL(rawURL, ...)
req, err := NewRequest(ri)
if err != nil {
...
}
client := NewHttpClient(true, 30 * time.Second)
dri := NewDoRequestInfo(req, auth, &responseRef) // or NewDoRequestInfoWithTimeout(..., ..., ..., requestTimeout)
err = client.Get(dri)
if err != nil {
...
}
Into this one:
ri := NewRequestInfo(scheme, host, ...) // or NewRequestInfoFromRawURL(rawURL, ...)
err := restclient.PerformGetRequest(ri, auth, &response, true, 30 * time.Second)
if err != nil {
...
}
Tests
There also exists carious tests (client_test
, request_test
) and assertions implemented to validate and verify that go-restclient
works.