diff options
| author | Paul Buetow <paul@buetow.org> | 2024-07-28 18:27:42 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-07-28 18:27:42 +0300 |
| commit | 8572fca487d124518e46f4fad1919cf98c5ae56a (patch) | |
| tree | e6f94e230422d3c16043909c768eba3adf3c92d6 /internal/easyhttp | |
| parent | 15e39ae8f63021fd599f6c1f3cfab9bf9c1885b0 (diff) | |
fix bug where POST turned out to be a HTTP get when there are // in the URI
Diffstat (limited to 'internal/easyhttp')
| -rw-r--r-- | internal/easyhttp/easyhttp.go | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/internal/easyhttp/easyhttp.go b/internal/easyhttp/easyhttp.go index 32a3069..ce3d53b 100644 --- a/internal/easyhttp/easyhttp.go +++ b/internal/easyhttp/easyhttp.go @@ -16,7 +16,7 @@ func Get(ctx context.Context, uri, apiKey string) ([]byte, error) { bytes []byte ) - req, err := http.NewRequestWithContext(ctx, "GET", uri, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, uri, nil) if err != nil { return bytes, fmt.Errorf("%s: %w", uri, err) } @@ -48,11 +48,12 @@ func GetData[T any](ctx context.Context, uri, apiKey string, data *T) error { } func Post(ctx context.Context, uri, apiKey string, data []byte) ([]byte, error) { - req, err := http.NewRequestWithContext(ctx, "POST", uri, bytes.NewBuffer(data)) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, uri, bytes.NewBuffer(data)) if err != nil { return []byte{}, fmt.Errorf("%s: %w", uri, err) } + req.Header.Set("Content-Type", "application/json") req.Header.Set("X-API-KEY", apiKey) client := &http.Client{} |
