(url string, reqJson *B1, respJson *B2)
| 174 | } |
| 175 | |
| 176 | func postRequestResponseJSON[B1 any, B2 any](url string, reqJson *B1, respJson *B2) error { |
| 177 | payload, err := json.Marshal(reqJson) |
| 178 | if err != nil { |
| 179 | return err |
| 180 | } |
| 181 | |
| 182 | GinkgoWriter.Printf("POST %s: %s\n", url, string(payload)) |
| 183 | |
| 184 | req, err := http.NewRequest("POST", url, bytes.NewBuffer(payload)) |
| 185 | if err != nil { |
| 186 | return err |
| 187 | } |
| 188 | |
| 189 | req.Header.Set("Content-Type", "application/json") |
| 190 | req.Header.Set("Authorization", bearerKey) |
| 191 | |
| 192 | client := &http.Client{} |
| 193 | resp, err := client.Do(req) |
| 194 | if err != nil { |
| 195 | return err |
| 196 | } |
| 197 | defer resp.Body.Close() |
| 198 | |
| 199 | body, err := io.ReadAll(resp.Body) |
| 200 | if err != nil { |
| 201 | return err |
| 202 | } |
| 203 | |
| 204 | if resp.StatusCode < 200 || resp.StatusCode >= 400 { |
| 205 | return fmt.Errorf("unexpected status code: %d, body: %s", resp.StatusCode, string(body)) |
| 206 | } |
| 207 | |
| 208 | return json.Unmarshal(body, respJson) |
| 209 | } |
| 210 | |
| 211 | func putRequestJSON[B any](url string, bodyJson *B) error { |
| 212 | payload, err := json.Marshal(bodyJson) |
no test coverage detected