(request)
| 473 | export { REST as default } |
| 474 | |
| 475 | function curlize(request) { |
| 476 | // Guard access to nested properties safely in case request.data is undefined |
| 477 | if ((request.data?.constructor?.name || '').toLowerCase() === 'formdata') return 'cURL is not printed as the request body is not a JSON' |
| 478 | let curl = `curl --location --request ${request.method ? request.method.toUpperCase() : 'GET'} ${request.baseURL} `.replace("'", '') |
| 479 | |
| 480 | if (request.headers) { |
| 481 | Object.entries(request.headers).forEach(([key, value]) => { |
| 482 | curl += `-H "${key}: ${value}" ` |
| 483 | }) |
| 484 | } |
| 485 | |
| 486 | if (!curl.toLowerCase().includes('content-type: application/json')) { |
| 487 | curl += '-H "Content-Type: application/json" ' |
| 488 | } |
| 489 | |
| 490 | if (request.data) { |
| 491 | curl += `-d '${JSON.stringify(request.data)}'` |
| 492 | } |
| 493 | return curl |
| 494 | } |
no test coverage detected