http.go
func (client *Client) Request(rawPayload []byte, method, route string, query url.Values) (*CallSummary, error) {
	callSummary := new(CallSummary)
	callSummary.HTTPRequestBody = string(rawPayload)

	// function to perform http request - we call this using backoff library to
	// have exponential backoff in case of intermittent failures (e.g. network
	// blips or HTTP 5xx errors)
	httpCall := func() (*http.Response, error, error) {
		var ioReader io.Reader
		ioReader = bytes.NewReader(rawPayload)
		u, err := setURL(client, route, query)
		if err != nil {
			return nil, nil, fmt.Errorf("apiCall url cannot be parsed:\n%v\n", err)
		}
		callSummary.HTTPRequest, err = http.NewRequest(method, u.String(), ioReader)
		if err != nil {
			return nil, nil, fmt.Errorf("Internal error: apiCall url cannot be parsed although thought to be valid: '%v', is the BaseURL (%v) set correctly?\n%v\n", u.String(), client.BaseURL, err)
		}
		if len(rawPayload) > 0 {
			callSummary.HTTPRequest.Header.Set("Content-Type", "application/json")
		}
		// Refresh Authorization header with each call...
		// Only authenticate if client library user wishes to.
		if client.Authenticate {
			err = client.Credentials.SignRequest(callSummary.HTTPRequest)
			if err != nil {
				return nil, nil, err
			}
		}
		// Set context if one is given
		if client.Context != nil {
			callSummary.HTTPRequest = callSummary.HTTPRequest.WithContext(client.Context)
		}
		var resp *http.Response
		if client.HTTPClient != nil {
			resp, err = client.HTTPClient.Do(callSummary.HTTPRequest)
		} else {
			resp, err = defaultHTTPClient.Do(callSummary.HTTPRequest)
		}
		// return cancelled error, if context was cancelled
		if client.Context != nil && client.Context.Err() != nil {
			return nil, nil, client.Context.Err()
		}
		// b, e := httputil.DumpResponse(resp, true)
		// if e == nil {
		// 	fmt.Println(string(b))
		// }
		return resp, err, nil
	}

	// Make HTTP API calls using an exponential backoff algorithm...
	var err error
	callSummary.HTTPResponse, callSummary.Attempts, err = httpbackoff.Retry(httpCall)

	// read response into memory, so that we can return the body
	if callSummary.HTTPResponse != nil {
		body, err2 := ioutil.ReadAll(callSummary.HTTPResponse.Body)
		if err2 == nil {
			callSummary.HTTPResponseBody = string(body)
		}
	}

	return callSummary, err

}
func (client *Client) Request(rawPayload []byte, method, route string, query url.Values) (*CallSummary, error) {
	callSummary := new(CallSummary)
	callSummary.HTTPRequestBody = string(rawPayload)

	// function to perform http request - we call this using backoff library to
	// have exponential backoff in case of intermittent failures (e.g. network
	// blips or HTTP 5xx errors)
	httpCall := func() (*http.Response, error, error) {
		var ioReader io.Reader
		ioReader = bytes.NewReader(rawPayload)
		u, err := setURL(client, route, query)
		if err != nil {
			return nil, nil, fmt.Errorf("apiCall url cannot be parsed:\n%v\n", err)
		}
		callSummary.HTTPRequest, err = http.NewRequest(method, u.String(), ioReader)
		if err != nil {
			return nil, nil, fmt.Errorf("Internal error: apiCall url cannot be parsed although thought to be valid: '%v', is the BaseURL (%v) set correctly?\n%v\n", u.String(), client.BaseURL, err)
		}
		if len(rawPayload) > 0 {
			callSummary.HTTPRequest.Header.Set("Content-Type", "application/json")
		}
		// Refresh Authorization header with each call...
		// Only authenticate if client library user wishes to.
		if client.Authenticate {
			err = client.Credentials.SignRequest(callSummary.HTTPRequest)
			if err != nil {
				return nil, nil, err
			}
		}
		// Set context if one is given
		if client.Context != nil {
			callSummary.HTTPRequest = callSummary.HTTPRequest.WithContext(client.Context)
		}
		var resp *http.Response
		if client.HTTPClient != nil {
			resp, err = client.HTTPClient.Do(callSummary.HTTPRequest)
		} else {
			resp, err = defaultHTTPClient.Do(callSummary.HTTPRequest)
		}
		// return cancelled error, if context was cancelled
		if client.Context != nil && client.Context.Err() != nil {
			return nil, nil, client.Context.Err()
		}
		// b, e := httputil.DumpResponse(resp, true)
		// if e == nil {
		// 	fmt.Println(string(b))
		// }
		return resp, err, nil
	}

	// Make HTTP API calls using an exponential backoff algorithm...
	var err error
	callSummary.HTTPResponse, callSummary.Attempts, err = httpbackoff.Retry(httpCall)

	// read response into memory, so that we can return the body
	if callSummary.HTTPResponse != nil {
		body, err2 := ioutil.ReadAll(callSummary.HTTPResponse.Body)
		if err2 == nil {
			callSummary.HTTPResponseBody = string(body)
		}
	}

	return callSummary, err

}
// Request is the underlying method that makes a raw API request, without
// performing any json marshaling/unmarshaling of requests/responses. It is
// useful if you wish to handle raw payloads and/or raw http response bodies,
// rather than calling APICall which translates []byte to/from go types.