| 138 | } |
| 139 | |
| 140 | func postRequestJSON[B any](url string, bodyJson *B) error { |
| 141 | payload, err := json.Marshal(bodyJson) |
| 142 | if err != nil { |
| 143 | return err |
| 144 | } |
| 145 | |
| 146 | GinkgoWriter.Printf("POST %s: %s\n", url, string(payload)) |
| 147 | |
| 148 | req, err := http.NewRequest("POST", url, bytes.NewBuffer(payload)) |
| 149 | if err != nil { |
| 150 | return err |
| 151 | } |
| 152 | |
| 153 | req.Header.Set("Content-Type", "application/json") |
| 154 | req.Header.Set("Authorization", bearerKey) |
| 155 | |
| 156 | client := &http.Client{} |
| 157 | resp, err := client.Do(req) |
| 158 | if err != nil { |
| 159 | return err |
| 160 | } |
| 161 | |
| 162 | defer resp.Body.Close() |
| 163 | |
| 164 | body, err := io.ReadAll(resp.Body) |
| 165 | if err != nil { |
| 166 | return err |
| 167 | } |
| 168 | |
| 169 | if resp.StatusCode < 200 || resp.StatusCode >= 400 { |
| 170 | return fmt.Errorf("unexpected status code: %d, body: %s", resp.StatusCode, string(body)) |
| 171 | } |
| 172 | |
| 173 | return nil |
| 174 | } |
| 175 | |
| 176 | func postRequestResponseJSON[B1 any, B2 any](url string, reqJson *B1, respJson *B2) error { |
| 177 | payload, err := json.Marshal(reqJson) |