Skip to content

Commit

Permalink
send API key through the header
Browse files Browse the repository at this point in the history
  • Loading branch information
phev8 committed May 12, 2022
1 parent 5068aa6 commit bab2e8f
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions pkg/studyengine/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"fmt"
"net/http"
"strings"
"time"

"github.com/coneno/logger"
"github.com/influenzanet/study-service/pkg/types"
)

Expand Down Expand Up @@ -78,17 +80,29 @@ func runHTTPcall(url string, APIkey string, payload ExternalEventPayload) (map[s
return nil, err
}

// TODO: send API key through header
resp, err := http.Post(url, "application/json", bytes.NewBuffer(json_data))
client := &http.Client{
Timeout: time.Second * 30,
}

req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(json_data))
if err != nil {
logger.Error.Printf("unexpected error: %v", err)
return nil, err
}
req.Header.Set("Api-Key", APIkey)
req.Header.Set("Content-Type", "application/json")

resp, err := client.Do(req)
if err != nil {
logger.Error.Printf("unexpected error: %v", err)
return nil, err
}

var res map[string]interface{}
err = json.NewDecoder(resp.Body).Decode(&res)
if err != nil {
logger.Error.Printf("unexpected error: %v", err)
return nil, err
}

return res, nil
}

0 comments on commit bab2e8f

Please sign in to comment.