Your commit message

This commit is contained in:
Prakash Maheshwaran
2025-06-05 06:01:36 -04:00
parent c4955e098a
commit 69ec20299f
7 changed files with 160 additions and 155 deletions

View File

@@ -0,0 +1,32 @@
import fetchToCurl from "fetch-to-curl";
export type ApiRequest = {
method: string;
url: string;
body?: unknown;
headers: Record<string, string>;
};
export function getCurlCommand(request: ApiRequest): string {
return fetchToCurl(request);
}
export function getPowerShellCommand(request: ApiRequest): string {
const { method, url, headers, body } = request;
const headerLines = Object.entries(headers)
.map(([key, value]) => ` '${key}' = '${value}'`)
.join("\n");
const bodyJson = body ? JSON.stringify(body, null, 2) : undefined;
const bodyLine = bodyJson
? ` Body = '${bodyJson.replace(/'/g, "''")}'\n`
: "";
return (
`$Params = @{\n` +
` Uri = '${url}'\n` +
` Method = '${method}'\n` +
` Headers = @{\n${headerLines}\n }\n` +
bodyLine +
`}\n` +
`Invoke-RestMethod @Params`
);
}