Skip to content

Commit 907c34a

Browse files
committed
chore: update getting started for frameworks (#843)
1 parent 5ebd08d commit 907c34a

19 files changed

+585
-969
lines changed

docs/clients/javascript.mdx

Lines changed: 133 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,141 @@
11
---
2-
title: JavaScript & TypeScript
3-
icon: js
2+
title: Node.js & Bun
3+
icon: node-js
44
---
55

6-
The ActorCore JavaScript client allows you to connect to and interact with actors from browser and Node.js applications.
7-
8-
## Installation
9-
10-
Install the ActorCore client package:
11-
12-
<CodeGroup>
13-
```sh npm
14-
npm add actor-core
15-
```
16-
17-
```sh pnpm
18-
pnpm add actor-core
19-
```
20-
21-
```sh yarn
22-
yarn add actor-core
23-
```
6+
import MvpWarning from "/snippets/mvp-warning.mdx";
7+
import StepDefineActor from "/snippets/step-define-actor.mdx";
8+
import StepRunStudio from "/snippets/step-run-studio.mdx";
9+
import StepDeploy from "/snippets/step-deploy.mdx";
10+
import SetupNextSteps from "/snippets/setup-next-steps.mdx";
2411

25-
```sh bun
26-
bun add actor-core
27-
```
28-
</CodeGroup>
29-
30-
## Connecting to an Actor
31-
32-
```typescript
33-
import { createClient } from "actor-core/client";
34-
import type { App } from "./app"; // Import type of ActorCore app for end-to-end type safety
35-
36-
// Create a client with the connection address
37-
const client = createClient<App>("http://localhost:6420");
38-
39-
// Connect to an actor
40-
const counter = await client.counter.get({ id: "counter-1" });
41-
42-
// Listen for events
43-
counter.on("newCount", (count) => {
44-
console.log(`Count updated: ${count}`);
45-
});
12+
The ActorCore JavaScript client allows you to connect to and interact with actors from browser and Node.js applications.
4613

47-
// Call an action on the actor
48-
const newCount = await counter.increment(5);
49-
console.log(`New count: ${newCount}`);
50-
```
14+
<MvpWarning />
15+
16+
## Quickstart
17+
18+
<Steps>
19+
<Step title="Create a new Node.js project">
20+
Create a new Node.js project with TypeScript support:
21+
22+
<CodeGroup>
23+
```sh npm
24+
mkdir my-app
25+
cd my-app
26+
npm init -y
27+
npm pkg set type=module
28+
```
29+
30+
```sh pnpm
31+
mkdir my-app
32+
cd my-app
33+
pnpm init
34+
pnpm pkg set type=module
35+
```
36+
37+
```sh yarn
38+
mkdir my-app
39+
cd my-app
40+
yarn init -y
41+
yarn pkg set type=module
42+
```
43+
44+
```sh bun
45+
mkdir my-app
46+
cd my-app
47+
bun init -y
48+
```
49+
</CodeGroup>
50+
</Step>
51+
52+
<Step title="Install ActorCore packages">
53+
Install the ActorCore client and Node.js platform packages:
54+
55+
<CodeGroup>
56+
```sh npm
57+
npm install actor-core
58+
```
59+
60+
```sh pnpm
61+
pnpm add actor-core
62+
```
63+
64+
```sh yarn
65+
yarn add actor-core
66+
```
67+
68+
```sh bun
69+
bun add actor-core
70+
```
71+
</CodeGroup>
72+
</Step>
73+
74+
<StepDefineActor />
75+
76+
<Step title="Create your client">
77+
Create a file `src/client.ts` in your project to connect to your actor:
78+
79+
```typescript src/client.ts
80+
import { createClient } from "actor-core/client";
81+
import type { App } from "../actors/app";
82+
83+
async function main() {
84+
// Replace with your endpoint URL after deployment
85+
const client = createClient<App>("http://localhost:6420");
86+
87+
// Get or create an actor instance
88+
const counter = await client.counter.get();
89+
90+
// Subscribe to events
91+
counter.on("newCount", (count: number) => console.log("Event:", count));
92+
93+
// Call an action
94+
const out = await counter.increment(5);
95+
console.log("Action:", out);
96+
97+
// Clean up when done
98+
await counter.dispose();
99+
}
100+
101+
main().catch(console.error);
102+
```
103+
</Step>
104+
105+
<StepRunStudio />
106+
107+
<Step title="Run your client">
108+
In a separate terminal, run your client code:
109+
110+
<CodeGroup>
111+
```sh npm
112+
npx tsx src/client.ts
113+
```
114+
115+
```sh pnpm
116+
pnpm exec tsx src/client.ts
117+
```
118+
119+
```sh yarn
120+
yarn tsx src/client.ts
121+
```
122+
123+
```sh bun
124+
bun run src/client.ts
125+
```
126+
</CodeGroup>
127+
128+
You should see output like:
129+
```
130+
Event: 5
131+
Action: 5
132+
```
133+
134+
Run it again to see the state update.
135+
</Step>
136+
137+
<StepDeploy />
138+
</Steps>
51139

52140
## Next Steps
53141

docs/clients/rust.mdx

Lines changed: 83 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,65 +3,99 @@ title: Rust
33
icon: rust
44
---
55

6+
import MvpWarning from "/snippets/mvp-warning.mdx";
7+
import StepDefineActor from "/snippets/step-define-actor.mdx";
8+
import StepRunStudio from "/snippets/step-run-studio.mdx";
9+
import StepDeploy from "/snippets/step-deploy.mdx";
10+
import SetupNextSteps from "/snippets/setup-next-steps.mdx";
11+
612
The ActorCore Rust client provides a way to connect to and interact with actors from Rust applications.
713

8-
## Installation
14+
<MvpWarning />
915

10-
Install the `actor-core-client` package with:
16+
## Quickstart
1117

12-
```sh
13-
cargo add actor-core-client serde-json
14-
```
18+
<Steps>
19+
<Step title="Create a new Rust project">
20+
Create a new Rust project:
21+
22+
```sh
23+
cargo new my-app
24+
cd my-app
25+
```
26+
</Step>
1527

16-
Make sure you have [Tokio](https://tokio.rs/) set up as your async runtime.
28+
<Step title="Add dependencies">
29+
Add ActorCore client & related dependencies to your project:
30+
31+
```sh
32+
cargo add actor-core-client
33+
cargo add serde_json
34+
cargo add tokio --features full
35+
```
36+
</Step>
1737

18-
## Connecting to an Actor
38+
<StepDefineActor />
1939

20-
```rust
21-
use actor_core_client::{Client, GetOptions, TransportKind, EncodingKind};
22-
use serde_json::json;
40+
<Step title="Create your client">
41+
Modify `src/main.rs` to connect to your actor:
2342

24-
#[tokio::main]
25-
async fn main() -> Result<(), Box<dyn std::error::Error>> {
26-
// Create a client with connection address and configuration
27-
let client = Client::new(
28-
"http://localhost:6420".to_string(), // Connection address
29-
TransportKind::WebSocket, // Transport type
30-
EncodingKind::Cbor, // Encoding format
31-
);
32-
33-
// Connect to an actor
34-
let tags = vec![
35-
("id".to_string(), "counter-1".to_string()),
36-
];
37-
38-
let options = GetOptions {
39-
tags: Some(tags),
40-
params: None,
41-
no_create: None,
42-
create: None,
43-
};
44-
45-
let counter = client.get("counter", options)
46-
.await?;
47-
48-
// Call an action on the actor
49-
let result = counter.action("increment", vec![json!(5)])
50-
.await?;
51-
let new_count = result.as_i64().unwrap();
52-
println!("New count: {}", new_count);
43+
```rust src/main.rs
44+
use actor_core_client::{Client, GetOptions, TransportKind, EncodingKind};
45+
use serde_json::json;
46+
use std::time::Duration;
47+
48+
#[tokio::main]
49+
async fn main() -> Result<(), Box<dyn std::error::Error>> {
50+
// Replace with your endpoint URL after deployment
51+
let client = Client::new(
52+
"http://localhost:6420".to_string(),
53+
TransportKind::WebSocket,
54+
EncodingKind::Cbor,
55+
);
56+
57+
// Get or create an actor instance
58+
let options = GetOptions::default();
59+
let counter = client.get("counter", options).await?;
60+
61+
// Subscribe to events
62+
counter.on_event("newCount", |args| {
63+
let count = args[0].as_i64().unwrap();
64+
println!("Event: {}", count);
65+
}).await;
66+
67+
// Call an action
68+
let result = counter.action("increment", vec![json!(5)]).await?;
69+
println!("Action: {}", result);
70+
71+
// Wait to receive events
72+
tokio::time::sleep(Duration::from_secs(1)).await;
73+
74+
Ok(())
75+
}
76+
```
77+
</Step>
78+
79+
<StepRunStudio />
80+
81+
<Step title="Run your client">
82+
In a separate terminal, run your client code:
5383

54-
// Listen for events
55-
counter.on_event("newCount", move |args| {
56-
let count = args[0].as_i64().unwrap();
57-
println!("Count updated: {}", count);
58-
}).await;
84+
```sh
85+
cargo run
86+
```
5987

60-
Ok(())
61-
}
62-
```
88+
You should see output like:
89+
```
90+
Event: 5
91+
Action: 5
92+
```
93+
94+
Run it again to see the state update.
95+
</Step>
6396

64-
## Next Steps
97+
<StepDeploy />
98+
</Steps>
6599

66-
See the [Interacting with Actors](/concepts/interacting-with-actors) documentation for information on how to use the client.
100+
<SetupNextSteps />
67101

docs/docs.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,18 @@
5050
{
5151
"group": "Get Started",
5252
"pages": [
53-
"platforms/rivet",
54-
"platforms/cloudflare-workers",
55-
"platforms/bun",
56-
"platforms/nodejs"
53+
"frameworks/react",
54+
"clients/javascript",
55+
"clients/rust"
5756
]
5857
},
5958
{
60-
"group": "Frameworks",
59+
"group": "Deploy",
6160
"pages": [
62-
"frameworks/react",
63-
"clients/javascript",
64-
"clients/rust"
61+
"platforms/rivet",
62+
"platforms/cloudflare-workers",
63+
"platforms/bun",
64+
"platforms/nodejs"
6565
]
6666
},
6767
{

docs/drivers/cloudflare-workers.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
2-
title: Durable Objects
2+
title: Cloudflare Workers (Durable Objects)
3+
sidebarTitle: Durable Objects
34
---
45

56
import DriverNote from '/snippets/driver-note.mdx';

0 commit comments

Comments
 (0)