0

Get HTTP request count

by
Published Oct 17, 2025

Get the HTTP request count for one or more resources.

Script render Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Render = {
3
	apiKey: string
4
}
5
/**
6
 * Get HTTP request count
7
 * Get the HTTP request count for one or more resources.
8

9
 */
10
export async function main(
11
	auth: Render,
12
	startTime: string | undefined,
13
	endTime: string | undefined,
14
	resolutionSeconds: string | undefined,
15
	resource: string | undefined,
16
	service: string | undefined,
17
	host: string | undefined,
18
	path: string | undefined,
19
	aggregateBy: 'statusCode' | 'host' | undefined
20
) {
21
	const url = new URL(`https://api.render.com/v1/metrics/http-requests`)
22
	for (const [k, v] of [
23
		['startTime', startTime],
24
		['endTime', endTime],
25
		['resolutionSeconds', resolutionSeconds],
26
		['resource', resource],
27
		['service', service],
28
		['host', host],
29
		['path', path],
30
		['aggregateBy', aggregateBy]
31
	]) {
32
		if (v !== undefined && v !== '' && k !== undefined) {
33
			url.searchParams.append(k, v)
34
		}
35
	}
36
	const response = await fetch(url, {
37
		method: 'GET',
38
		headers: {
39
			Authorization: 'Bearer ' + auth.apiKey
40
		},
41
		body: undefined
42
	})
43
	if (!response.ok) {
44
		const text = await response.text()
45
		throw new Error(`${response.status} ${text}`)
46
	}
47
	return await response.json()
48
}
49