(endpoint, method, body = null)
| 1 | function generateExamples(endpoint, method, body = null) { |
| 2 | let curlBodyString = ''; |
| 3 | let psBodyString = ''; |
| 4 | |
| 5 | if (body) { |
| 6 | const curlJsonString = JSON.stringify(body).replace(/"/g, '\\"'); |
| 7 | curlBodyString = ` -d "${curlJsonString}"`; |
| 8 | psBodyString = `-Body (ConvertTo-Json ${JSON.stringify(body)})`; |
| 9 | } |
| 10 | |
| 11 | return { |
| 12 | cURL: `curl -u user:pass -H "Content-Type: application/json" -X ${method.trim()} -k https://localhost:47990${endpoint.trim()}${curlBodyString}`, |
| 13 | Python: `import json |
| 14 | import requests |
| 15 | from requests.auth import HTTPBasicAuth |
| 16 | |
| 17 | requests.${method.trim().toLowerCase()}( |
| 18 | auth=HTTPBasicAuth('user', 'pass'), |
| 19 | url='https://localhost:47990${endpoint.trim()}', |
| 20 | verify=False,${body ? `\n json=${JSON.stringify(body)},` : ''} |
| 21 | ).json()`, |
| 22 | JavaScript: `fetch('https://localhost:47990${endpoint.trim()}', { |
| 23 | method: '${method.trim()}', |
| 24 | headers: { |
| 25 | 'Authorization': 'Basic ' + btoa('user:pass'), |
| 26 | 'Content-Type': 'application/json', |
| 27 | }${body ? `,\n body: JSON.stringify(${JSON.stringify(body)}),` : ''} |
| 28 | }) |
| 29 | .then(response => response.json()) |
| 30 | .then(data => console.log(data));`, |
| 31 | PowerShell: `Invoke-RestMethod \` |
| 32 | -SkipCertificateCheck \` |
| 33 | -ContentType 'application/json' \` |
| 34 | -Uri 'https://localhost:47990${endpoint.trim()}' \` |
| 35 | -Method ${method.trim()} \` |
| 36 | -Headers @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes('user:pass'))} |
| 37 | ${psBodyString}` |
| 38 | }; |
| 39 | } |
| 40 | |
| 41 | function hashString(str) { |
| 42 | let hash = 0; |
nothing calls this directly
no outgoing calls
no test coverage detected