0

List redirect/rewrite rules

by
Published Oct 17, 2025

List a particular service's redirect/rewrite rules that match the provided filters. If no filters are provided, all rules for the service are returned.

Script render Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Render = {
3
	apiKey: string
4
}
5
/**
6
 * List redirect/rewrite rules
7
 * List a particular service's redirect/rewrite rules that match the provided filters. If no filters are provided, all rules for the service are returned.
8

9
 */
10
export async function main(
11
	auth: Render,
12
	serviceId: string,
13
	_type: string | undefined,
14
	source: string | undefined,
15
	destination: string | undefined,
16
	cursor: string | undefined,
17
	limit: string | undefined
18
) {
19
	const url = new URL(`https://api.render.com/v1/services/${serviceId}/routes`)
20
	for (const [k, v] of [
21
		['type', _type],
22
		['source', source],
23
		['destination', destination],
24
		['cursor', cursor],
25
		['limit', limit]
26
	]) {
27
		if (v !== undefined && v !== '' && k !== undefined) {
28
			url.searchParams.append(k, v)
29
		}
30
	}
31
	const response = await fetch(url, {
32
		method: 'GET',
33
		headers: {
34
			Authorization: 'Bearer ' + auth.apiKey
35
		},
36
		body: undefined
37
	})
38
	if (!response.ok) {
39
		const text = await response.text()
40
		throw new Error(`${response.status} ${text}`)
41
	}
42
	return await response.json()
43
}
44