Overview
Access the Durable Objects API:Namespaces
Durable Object namespaces are containers for Durable Object instances.List namespaces
Retrieve all Durable Object namespaces in your account.string
required
Your Cloudflare account ID
number
Page number for pagination
number
Number of namespaces per page (default: 20, max: 100)
string
The namespace ID
string
The namespace name
string
The Worker script that defines the Durable Object class
string
The exported class name in the Worker script
Creating Durable Objects
Durable Objects are created through Worker bindings. You define the class in your Worker script and bind it using migrations.Example: Define a Durable Object class
In your Worker script:Example: Configure bindings
When deploying your Worker, configure Durable Object bindings:string
required
Set to ‘durable_object_namespace’
string
required
The binding name (accessible as env.COUNTER in your Worker)
string
required
The exported Durable Object class name
string
The Worker script that exports the class (defaults to current script)
Migrations
When deploying Workers with Durable Objects, you need to specify migrations to create, rename, or delete Durable Object classes.Example: Create a new Durable Object class
array
Array of class names to create
array
Array of objects with ‘from’ and ‘to’ properties for renaming classes
array
Array of class names to delete
array
Array of class names to create with SQLite storage
Example: Rename a Durable Object class
Using Durable Objects in Workers
Once configured, access Durable Objects from your Worker:Best practices
- Unique IDs: Use
idFromName()for deterministic IDs ornewUniqueId()for random IDs - State management: Use
state.storagefor persistent data with strong consistency - Concurrency: Durable Objects handle one request at a time, ensuring strong consistency
- Migrations: Always specify migrations when adding, renaming, or removing Durable Object classes
- SQLite storage: Use
new_sqlite_classesfor SQL-based storage in Durable Objects