# Workflows Pipeline Demo (/docs/experiments/workflows-pipeline-demo)



A durable three-step pipeline built with **Cloudflare Workflows**: fetch a URL, pause with `step.sleep()`, summarize the page with Workers AI, and store the JSON result in R2. Poll status by workflow instance ID.

## Features [#features]

* **POST /run** - Start a workflow instance from a URL
* **GET /status/:instanceId** - Poll status and final output
* **Three durable steps** - fetch, summarize, store (each wrapped in `step.do()`)
* **Pause demo** - `step.sleep("3 seconds")` between fetch and summarize

## API Reference [#api-reference]

### POST /run [#post-run]

Start a new workflow instance.

<TypeTable
  type="{
  url: {
    description: &#x22;Target page URL (http or https only).&#x22;,
    type: &#x22;string&#x22;,
    required: true,
  },
}"
/>

#### Example Request [#example-request]

```bash
curl -X POST "https://your-worker.workers.dev/run" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://example.com"}'
```

#### Success Response (202) [#success-response-202]

```json
{
  "instanceId": "abc-123",
  "status": "running"
}
```

#### Error Codes [#error-codes]

* `400` - Invalid JSON (`INVALID_BODY`) or URL (`INVALID_URL`)
* `502` - Workflow start failed (`WORKFLOW_ERROR`)

### GET /status/:instanceId [#get-statusinstanceid]

Poll workflow status and result.

#### Example Request [#example-request-1]

```bash
curl "https://your-worker.workers.dev/status/abc-123"
```

#### Success Response [#success-response]

```json
{
  "instanceId": "abc-123",
  "status": "complete",
  "output": {
    "url": "https://example.com/",
    "summary": "Example Domain is a placeholder site for documentation examples.",
    "r2Key": "summaries/abc-123.json"
  },
  "error": null
}
```

#### Error Codes [#error-codes-1]

* `400` - Missing instance id (`INVALID_INSTANCE_ID`)
* `404` - Instance not found (`NOT_FOUND`)

## Use Cases [#use-cases]

* Learn `WorkflowEntrypoint`, `step.do()`, and `step.sleep()` patterns
* Build durable multi-step pipelines that survive retries and pauses
* Combine Workflows with Workers AI and R2 in one reference worker

## Limitations [#limitations]

* Demo HTML extraction is basic (title + stripped tags); not suitable for complex SPAs
* Requires R2 bucket, Workers AI, and Workflows enabled on your account
* Workflow sleep adds latency by design for the demo

## Deployment [#deployment]

<Steps>
  <Step>
    ### Click the deploy button [#click-the-deploy-button]

    [![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/shrinathsnayak/cloudflare-experiments/tree/main/apps/experiments/workflows-pipeline-demo)
  </Step>

  <Step>
    ### Configure bindings [#configure-bindings]

    Create R2 bucket `workflows-pipeline-summaries` and enable Workers AI. The workflow binding is declared in `wrangler.json`.
  </Step>

  <Step>
    ### Test your deployment [#test-your-deployment]

    ```bash
    curl -X POST "https://your-worker.workers.dev/run" \
      -H "Content-Type: application/json" \
      -d '{"url":"https://example.com"}'
    ```
  </Step>
</Steps>

## Local Development [#local-development]

```bash
cd apps/experiments/workflows-pipeline-demo
npm install
npm run dev
```

## Configuration [#configuration]

| Binding     | Purpose                                       |
| ----------- | --------------------------------------------- |
| `PIPELINE`  | Cloudflare Workflow (`SummaryPipeline` class) |
| `AI`        | Workers AI summarization                      |
| `SUMMARIES` | R2 bucket for stored JSON summaries           |

## Cloudflare Features Used [#cloudflare-features-used]

* **[Workers](https://developers.cloudflare.com/workers/)** - Edge compute runtime
* **[Workflows](https://developers.cloudflare.com/workflows/)** - Durable multi-step execution
* **[Workers AI](https://developers.cloudflare.com/workers-ai/)** - LLM summarization
* **[R2](https://developers.cloudflare.com/r2/)** - Object storage for pipeline output
