diff --git a/api_client.go b/api_client.go index a3250ca..1b2b767 100644 --- a/api_client.go +++ b/api_client.go @@ -142,6 +142,13 @@ func (client *ApiClient) Get(path string) (*http.Response, error) { return client.do(request) } +func (client *ApiClient) GetParams(path string, params *url.Values) (*http.Response, error) { + if params != nil { + path = path + "?" + params.Encode() + } + return client.Get(path) +} + func (client *ApiClient) Post(path, contentType string, body io.Reader) (*http.Response, error) { destUrl, err := url.JoinPath(client.baseUrl, path) if err != nil { diff --git a/api_client_http_test.go b/api_client_http_test.go index 06b9f4f..501826c 100644 --- a/api_client_http_test.go +++ b/api_client_http_test.go @@ -4,6 +4,7 @@ import ( "io" "net/http" "net/http/httptest" + "net/url" "strings" "testing" "time" @@ -106,3 +107,25 @@ func TestPost(t *testing.T) { assert.NoError(t, err, "failed to read response body") assert.Equal(t, `"ho"`, string(body), "Didn't get expected response") } + +func TestGetParams(t *testing.T) { + ct := newClientTest( + http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, "/some-path?some-param=some-value", r.URL.Path, "didn't get the expected path") + }), + ) + defer ct.Close() + + resp, err := ct.apiClient.GetParams( + "/some-path", + &url.Values{ + "some-param": []string{"some-value"}, + }, + ) + assert.NoError(t, err, "failed to make get request") + defer resp.Body.Close() + + body, err := io.ReadAll(resp.Body) + assert.NoError(t, err, "failed to read response body") + assert.Equal(t, []byte{}, body) +}