---
# System prepended metadata

title: State.world

---

# State.world

```
type key = string
type value = list<u8> // Or application-defined type?

import load: func(key: key) -> result<value, error>

export serialize: func() -> result<list<(key, value)>, error>
```

# pubsub/Types.wit

```
enum error {...}
type channel-id = string // or UUID? or a Handle?
type message = list<u8>
```

# pubsub/Publish.wit

```
use { channel-id, message, error } from "pubsub/Types"

publish: func(channel: channel-id, message: message) -> result<(), error>
```

# pubsub/Subscribe.wit

```
use { channel-id, message, error } from "pubsub/Types"

subscribe: func(channel: channel-id) -> result<(), error>
```

# pubsub/Receive.wit

```
use { channel-id, message } from "pubsub/Types"

receive: func(channel: channel-id, message: message) -> ()
```

# WebSocket.world

```
extend "State"
export "pubsub/Receive"
use { request, response } from "http/Types"

enum error { ... }
type frame = list<u8>
type frames = list<frame>

export handle-connect: func(req: request, channel: channel-id)
   -> response

export handle-disconnect: func() -> ()

import send-frames: func(frames: frames) -> result<(), error>

export receive-frames: func(frames: frames) -> ()
```