Skip to content

Commit db8e8d1

Browse files
committed
Add quickstart example
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
1 parent f44715b commit db8e8d1

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

docs/platform/typescript-sdk.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,47 @@ npm install @slicervm/sdk
88

99
The SDK ships dual ESM + CommonJS builds with full TypeScript types. Node 18 or later is required.
1010

11+
## Quickstart
12+
13+
Create a VM, run a command, delete the VM:
14+
15+
```ts
16+
import { SlicerClient, GiB } from '@slicervm/sdk';
17+
18+
const client = SlicerClient.fromEnv(); // reads SLICER_URL + SLICER_TOKEN
19+
20+
const vm = await client.vms.create(
21+
'sbox',
22+
{ cpus: 1, ramBytes: GiB(1) },
23+
{ wait: 'agent', waitTimeoutSec: 60 },
24+
);
25+
console.log(`created ${vm.hostname} (${vm.ip})`);
26+
27+
try {
28+
const result = await vm.execBuffered({ command: 'uname', args: ['-a'] });
29+
console.log(`exit=${result.exitCode}`);
30+
console.log(result.stdout.trim());
31+
} finally {
32+
await vm.delete();
33+
}
34+
```
35+
36+
Run it:
37+
38+
```bash
39+
SLICER_URL=~/slicer-mac/slicer.sock npx tsx run-command.ts
40+
```
41+
42+
Expected output:
43+
44+
```
45+
created sbox-1 (192.168.64.3)
46+
exit=0
47+
Linux sbox-1 6.12.70 #1 SMP aarch64 GNU/Linux
48+
```
49+
50+
The complete runnable source — with logging, env handling, and a remote-daemon variant — is in [`examples/run-command/`](https://github.com/slicervm/sdk-ts/tree/master/examples/run-command).
51+
1152
## Shape
1253

1354
The SDK has two layers:
@@ -270,7 +311,7 @@ The SDK base64-encodes secret data transparently; pass plaintext.
270311
## Examples
271312

272313
* [Video conversion with TypeScript](/platform/typescript-video-conversion/) — create a VM, install ffmpeg, transcode a video, and stream the binary result back via `stdio: 'base64'`. Full e2e walkthrough with runnable source.
273-
* [`examples/` in the SDK repo](https://github.com/slicervm/sdk-ts/tree/main/examples) — more runnable examples.
314+
* [`examples/` in the SDK repo](https://github.com/slicervm/sdk-ts/tree/master/examples) — more runnable examples.
274315

275316
## See also
276317

docs/platform/typescript-video-conversion.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A full end-to-end example that uses the [TypeScript SDK](/platform/typescript-sdk/) to create a microVM, install ffmpeg, transcode a video, and stream the binary result back — without an intermediate file on the guest disk.
44

5-
The complete, runnable source is in [`examples/ffmpeg/`](https://github.com/slicervm/sdk-ts/tree/main/examples/ffmpeg) in the SDK repository.
5+
The complete, runnable source is in [`examples/ffmpeg/`](https://github.com/slicervm/sdk-ts/tree/master/examples/ffmpeg) in the SDK repository.
66

77
For the Go equivalent, see [Video Conversion (Go)](/platform/video-conversion/).
88

@@ -163,4 +163,4 @@ Most of the wall time is `apt install ffmpeg`. For repeat runs:
163163
* [TypeScript SDK reference](/platform/typescript-sdk/) — all methods and types.
164164
* [Video Conversion (Go)](/platform/video-conversion/) — same workflow, Go SDK.
165165
* [REST API reference](/reference/api/) — the underlying HTTP endpoints.
166-
* [Example source on GitHub](https://github.com/slicervm/sdk-ts/tree/main/examples/ffmpeg)
166+
* [Example source on GitHub](https://github.com/slicervm/sdk-ts/tree/master/examples/ffmpeg)

0 commit comments

Comments
 (0)