Skip to content

Commit ea16ed7

Browse files
author
Mathieu Grzybek
committed
[utils] create a dedicated function to send get requests to the API
1 parent 2498514 commit ea16ed7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

utils/api.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package utils
2+
3+
import (
4+
"io"
5+
"net/http"
6+
)
7+
8+
func CallAPIGet(url, token string) ([]byte, error) {
9+
req, _ := http.NewRequest("GET", url, nil)
10+
req.Header.Add("Authorization", "Bearer "+token)
11+
req.Header.Set("Content-Type", "application/json")
12+
13+
client := &http.Client{}
14+
res, e := client.Do(req)
15+
if e != nil {
16+
return []byte(""), e
17+
}
18+
body, e := io.ReadAll(res.Body)
19+
20+
return body, e
21+
}

0 commit comments

Comments
 (0)