MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / curlize

Function curlize

lib/helper/REST.js:475–494  ·  view source on GitHub ↗
(request)

Source from the content-addressed store, hash-verified

473export { REST as default }
474
475function 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}

Callers 1

_executeRequestMethod · 0.85

Calls 2

entriesMethod · 0.80
includesMethod · 0.80

Tested by

no test coverage detected