diff --git a/helper.go b/helper.go index 73e5428..700e242 100644 --- a/helper.go +++ b/helper.go @@ -1,17 +1,20 @@ package helper import ( + "bytes" + "encoding/json" "fmt" "net/http" ) func Get(uri string, authName string, authValue string, queries map[string]string) (*http.Response, error) { - client := &http.Client{} - request, err := http.NewRequest("GET", uri, nil) if err != nil { return nil, err } + + client := &http.Client{} + request.Header.Set("Accept", "application/json") request.Header.Set("Authorization", fmt.Sprintf("%s %s", authName, authValue)) @@ -32,3 +35,28 @@ func Get(uri string, authName string, authValue string, queries map[string]strin return response, nil } + +func Post(uri string, authName string, authValue string, data any) (*http.Response, error) { + jsonBytes, err := json.Marshal(data) + if err != nil { + return nil, err + } + + body := bytes.NewBuffer(jsonBytes) + request, err := http.NewRequest("POST", uri, body) + if err != nil { + return nil, err + } + + client := &http.Client{} + + request.Header.Set("Content-Type", "application/json") + request.Header.Set("Authorization", fmt.Sprintf("%s %s", authName, authValue)) + + response, err := client.Do(request) + if err != nil { + return nil, err + } + + return response, nil +}