MCPcopy Create free account
hub / github.com/ClassicOldSong/Apollo / generateExamples

Function generateExamples

docs/api.js:1–39  ·  view source on GitHub ↗
(endpoint, method, body = null)

Source from the content-addressed store, hash-verified

1function 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
14import requests
15from requests.auth import HTTPBasicAuth
16
17requests.${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
41function hashString(str) {
42 let hash = 0;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected