---
description: Code examples demonstrating common Durable Objects patterns, including counters, WebSockets, and alarms.
title: Examples
image: https://developers.cloudflare.com/og-docs.png
---

[Skip to content](#main-content)

> Documentation Index  
> Fetch the complete documentation index at: https://developers.cloudflare.com/durable-objects/llms.txt  
> Use this file to discover all available pages before exploring further.

# Examples

Last updated Aug 24, 2026|Copy as Markdown|[View as Markdown](https://e8aee267.previews.developers.cloudflare.com/durable-objects/examples/index.md)|[Agent setup](https://e8aee267.previews.developers.cloudflare.com/agent-setup/)

Explore the following examples for Durable Objects.

[**Use ReadableStream with Durable Object and Workers**Stream ReadableStream from Durable Objects.](https://e8aee267.previews.developers.cloudflare.com/durable-objects/examples/readable-stream/)

[**Use RpcTarget class to handle Durable Object metadata**Access the name from within a Durable Object using RpcTarget.](https://e8aee267.previews.developers.cloudflare.com/durable-objects/examples/reference-do-name-using-init/)

[**Durable Object Time To Live**Use the Durable Objects Alarms API to implement a Time To Live (TTL) for Durable Object instances.](https://e8aee267.previews.developers.cloudflare.com/durable-objects/examples/durable-object-ttl/)

[**Build a WebSocket server with WebSocket Hibernation**Build a WebSocket server using WebSocket Hibernation on Durable Objects and Workers.](https://e8aee267.previews.developers.cloudflare.com/durable-objects/examples/websocket-hibernation-server/)

[**Build a WebSocket server**Build a WebSocket server using Durable Objects and Workers.](https://e8aee267.previews.developers.cloudflare.com/durable-objects/examples/websocket-server/)

[**Use the Alarms API**Use the Durable Objects Alarms API to batch requests to a Durable Object.](https://e8aee267.previews.developers.cloudflare.com/durable-objects/examples/alarms-api/)

[**Durable Objects - Use KV within Durable Objects**Read and write to/from KV within a Durable Object](https://e8aee267.previews.developers.cloudflare.com/durable-objects/examples/use-kv-from-durable-objects/)

[**Testing Durable Objects**Write tests for Durable Objects using the Workers Vitest integration.](https://e8aee267.previews.developers.cloudflare.com/durable-objects/examples/testing-with-durable-objects/)

[**Build a counter**Build a counter using Durable Objects and Workers with RPC methods.](https://e8aee267.previews.developers.cloudflare.com/durable-objects/examples/build-a-counter/)

[**Durable Object in-memory state**Create a Durable Object that stores the last location it was accessed from in-memory.](https://e8aee267.previews.developers.cloudflare.com/durable-objects/examples/durable-object-in-memory-state/)

Was this helpful?

YesNo

## On this page

[![](https://e8aee267.previews.developers.cloudflare.com/_astro/logo.te5VL_aD.svg)Docs](https://e8aee267.previews.developers.cloudflare.com/)

```json
{"@context":"https://schema.org","@type":"WebPage","@id":"https://developers.cloudflare.com/durable-objects/examples/#page","headline":"Examples · Cloudflare Durable Objects docs","description":"Code examples demonstrating common Durable Objects patterns, including counters, WebSockets, and alarms.","url":"https://developers.cloudflare.com/durable-objects/examples/","inLanguage":"en","image":"https://developers.cloudflare.com/og-docs.png","dateModified":"2026-08-24","publisher":{"@type":"Organization","name":"Cloudflare","url":"https://www.cloudflare.com/"},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
```
