Partitions
Partitions are instances of your application in the registered domain. They allow you to create multiple isolated instances of your application, each with its own state and data.
Overview
Partitions are a fundamental concept in Capela that allow you to:
- Isolate Data: Each partition has its own isolated data
- Scale Applications: Create multiple instances of your application
- Manage State: Each partition maintains its own state
- Control Access: Control access to your application data
Creating Partitions
To create a partition, you need to:
- Register a domain
- Deploy your application
- Create a partition
Step 1: Register a Domain
Before you can create a partition, you need to register a domain:
# Register the test asmc.ai domain
http POST 'http://127.0.0.1:22440/g/!sys/namezone/"ai"' object_type=builtins.NameZone
http POST 'http://127.0.0.1:22440/g/!sys/namezone/ai/"asmc"' object_type=builtins.NameZone
Step 2: Deploy Your Application
After registering a domain, you need to deploy your application:
# Deploy the hello application
uvmc deploy apps/hello
Step 3: Create a Partition
Once your application is deployed, you can create a partition:
# Create a partition
http POST 'http://localhost:22440/partitions' object_type=ai.asmc.hello.hello.Hello
The response header will contain your app's location:
content-location: !9ea0d673eb4473b26124128c4539803f7413ee00ee7bdcdb87137b35a16ce58b
Using Partitions
Once you have created a partition, you can interact with it using the API routes. Each response includes a content-location header that provides the canonical path to the accessed item.
Partition Paths
Partitions can be accessed using either:
- The full path with
%0notation (e.g.,/!9ea0d673eb4473b26124128c4539803f7413ee00ee7bdcdb87137b35a16ce58b/%0) - The human-readable path (e.g.,
/go/to/path)
Calling Functions
You can call functions on your partition using the /d/ routes:
# Call the say_hello_to function
http POST 'http://localhost:22440/d/!9ea0d673eb4473b26124128c4539803f7413ee00ee7bdcdb87137b35a16ce58b/say_hello_to' name="Alice"
Fetching and Modifying State Variables
You can fetch and modify state variables from your partition using the /g/ routes:
# Fetch the count variable
http GET 'http://localhost:22440/g/!9ea0d673eb4473b26124128c4539803f7413ee00ee7bdcdb87137b35a16ce58b/count'
# Set a value in a dictionary
http POST 'http://localhost:22440/g/!9ea0d673eb4473b26124128c4539803f7413ee00ee7bdcdb87137b35a16ce58b/exampleDict/"new_key"' --raw 5
# Set a value in an array
http POST 'http://localhost:22440/g/!9ea0d673eb4473b26124128c4539803f7413ee00ee7bdcdb87137b35a16ce58b/exampleArray/0' --raw "new_value"
WebSocket SDK
You can also interact with partitions using the WebSocket SDK.
See the WebSocket page for more information.