-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdemo.ts
executable file
·48 lines (42 loc) · 1.17 KB
/
demo.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env -S deno run --unstable --allow-env
import { TextLineStream } from './deps.ts';
import { autoDetectClient } from './mod.ts';
const client = await autoDetectClient();
// Grab a single resource as JSON
console.log(await client.performRequest({
method: 'GET',
path: `/api/v1/namespaces/default/endpoints`,
expectJson: true,
querystring: new URLSearchParams({
limit: '1',
}),
}));
// Stream multiple JSON objects for a Watch operation
for await (const line of await client.performRequest({
method: 'GET',
path: `/api/v1/namespaces/default/endpoints`,
expectStream: true,
expectJson: true,
querystring: new URLSearchParams({
watch: '1',
timeoutSeconds: '1',
}),
})) {
console.log(line);
}
// Stream plaintext log lines from a pod
const lineStream = await client.performRequest({
method: 'GET',
path: `/api/v1/namespaces/default/pods/lambdabot-0/log`,
expectStream: true,
querystring: new URLSearchParams({
timestamps: '1',
tailLines: '15',
}),
}).then(x => x
.pipeThrough(new TextDecoderStream('utf-8'))
.pipeThrough(new TextLineStream()));
for await (const line of lineStream) {
console.log(line);
}
console.log('done');