MCPcopy Index your code
hub / github.com/simstudioai/sim / processUrl

Function processUrl

apps/sim/tools/http/utils.ts:50–84  ·  view source on GitHub ↗
(
  url: string,
  pathParams?: Record<string, string>,
  queryParams?: TableRow[] | Record<string, any> | string | null
)

Source from the content-addressed store, hash-verified

48 * @returns Processed URL with path params replaced and query params added
49 */
50export const processUrl = (
51 url: string,
52 pathParams?: Record<string, string>,
53 queryParams?: TableRow[] | Record<string, any> | string | null
54): string => {
55 if ((url.startsWith('"') && url.endsWith('"')) || (url.startsWith("'") && url.endsWith("'"))) {
56 url = url.slice(1, -1)
57 }
58
59 if (pathParams) {
60 Object.entries(pathParams).forEach(([key, value]) => {
61 url = url.replace(`:${key}`, encodeURIComponent(value))
62 })
63 }
64
65 if (queryParams) {
66 const queryParamsObj = transformTable(queryParams)
67
68 const separator = url.includes('?') ? '&' : '?'
69
70 const queryParts: string[] = []
71
72 for (const [key, value] of Object.entries(queryParamsObj)) {
73 if (value !== undefined && value !== null) {
74 queryParts.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`)
75 }
76 }
77
78 if (queryParts.length > 0) {
79 url += separator + queryParts.join('&')
80 }
81 }
82
83 return url
84}

Callers 1

request.tsFile · 0.90

Calls 4

transformTableFunction · 0.90
joinMethod · 0.80
replaceMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected