---
title: Local development · Cloudflare for Platforms docs
description: To test your Dispatch Worker, user Worker and Outbound Worker before deploying to production, you can use Wrangler for development and testing.
source_url:
  html: https://e68be143.preview.developers.cloudflare.com/cloudflare-for-platforms/workers-for-platforms/get-started/developing-with-wrangler/index.md
  md: https://e68be143.preview.developers.cloudflare.com/cloudflare-for-platforms/workers-for-platforms/get-started/developing-with-wrangler/
---

To test your [Dispatch Worker](https://developers.cloudflare.com/cloudflare-for-platforms/workers-for-platforms/reference/how-workers-for-platforms-works/#dynamic-dispatch-worker), [user Worker](https://developers.cloudflare.com/cloudflare-for-platforms/workers-for-platforms/reference/how-workers-for-platforms-works/#user-workers) and [Outbound Worker](https://developers.cloudflare.com/cloudflare-for-platforms/workers-for-platforms/configuration/outbound-workers/) before deploying to production, you can use [Wrangler](https://developers.cloudflare.com/workers/wrangler) for development and testing.

Note

Support for Workers for Platforms with `wrangler dev` in local mode is experimental and may change in the future. Use the prerelease branch: `wrangler@dispatch-namespaces-dev` to try Workers for Platforms locally.

## 1. Create a user worker

* npm

  ```sh
  npm create cloudflare@latest -- customer-worker-1
  ```

* pnpm

  ```sh
  pnpm create cloudflare@latest customer-worker-1
  ```

* yarn

  ```sh
  yarn create cloudflare customer-worker-1
  ```

For setup, select the following options:

* For *What would you like to start with?*, choose `Hello World Starter`.
* For *Which template would you like to use?*, choose `Worker only`.
* For *Which language do you want to use?*, choose `JavaScript`.
* For *Do you want to use git for version control?*, choose `Yes`.
* For *Do you want to deploy your application?*, choose `No` (we will be making some changes before deploying).

Then, move into the newly created directory:

```sh
cd customer-worker-1
```

Update the `src/index.js` file for customer-worker-1:

```javascript
export default {
  async fetch(request) {
    // make a subrequest to the internet
    const response = await fetch("https://example.com");
    return new Response(
      `user worker got "${await response.text()}" from fetch`,
    );
  },
};
```

Update the Wrangler file for customer-worker-1 and add the dispatch namespace:

* wrangler.jsonc

  ```jsonc
  {
    "dispatch_namespace": "my-namespace"
  }
  ```

* wrangler.toml

  ```toml
  # ... other content above ...


  dispatch_namespace = "my-namespace"
  ```

## 2. Create a dispatch worker

* npm

  ```sh
  npm create cloudflare@latest -- dispatch-worker
  ```

* pnpm

  ```sh
  pnpm create cloudflare@latest dispatch-worker
  ```

* yarn

  ```sh
  yarn create cloudflare dispatch-worker
  ```

For setup, select the following options:

* For *What would you like to start with?*, choose `Hello World Starter`.
* For *Which template would you like to use?*, choose `Worker only`.
* For *Which language do you want to use?*, choose `JavaScript`.
* For *Do you want to use git for version control?*, choose `Yes`.
* For *Do you want to deploy your application?*, choose `No` (we will be making some changes before deploying).

Then, move into the newly created directory:

```sh
cd dispatch-worker
```

Update the `src/index.js` file for dispatch-worker:

```javascript
export default {
  async fetch(request, env) {
    // get the user Worker, specifying parameters that the Outbound Worker will see when it intercepts a user worker's subrequest
    const customerScript = env.DISPATCH_NAMESPACE.get(
      "customer-worker-1",
      {},
      {
        outbound: {
          paramCustomerName: "customer-1",
        },
      },
    );
    // invoke user Worker
    return await customerScript.fetch(request);
  },
};
```

Update the Wrangler file for dispatch-worker and add the dispatch namespace binding:

* wrangler.jsonc

  ```jsonc
  {
    "dispatch_namespaces": [
      {
        "binding": "DISPATCH_NAMESPACE",
        "namespace": "my-namespace",
        "outbound": {
          "service": "outbound-worker",
          "parameters": [
            "paramCustomerName"
          ]
        }
      }
    ]
  }
  ```

* wrangler.toml

  ```toml
  # ... other content above ...


  [[dispatch_namespaces]]
  binding = "DISPATCH_NAMESPACE"
  namespace = "my-namespace"
  outbound = { service = "outbound-worker", parameters = ["paramCustomerName"] }
  ```

## 3. Create an Outbound Worker

* npm

  ```sh
  npm create cloudflare@latest -- outbound-worker
  ```

* pnpm

  ```sh
  pnpm create cloudflare@latest outbound-worker
  ```

* yarn

  ```sh
  yarn create cloudflare outbound-worker
  ```

For setup, select the following options:

* For *What would you like to start with?*, choose `Hello World Starter`.
* For *Which template would you like to use?*, choose `Worker only`.
* For *Which language do you want to use?*, choose `JavaScript`.
* For *Do you want to use git for version control?*, choose `Yes`.
* For *Do you want to deploy your application?*, choose `No` (we will be making some changes before deploying).

Then, move into the newly created directory:

```sh
cd outbound-worker
```

Update the `src/index.js` file for outbound-worker:

```javascript
export default {
  async fetch(request, env) {
    const { paramCustomerName } = env;
    // use the parameters passed by the dispatcher to know what this user this request is for
    // and return custom content back to the user worker
    return new Response(
      `intercepted a request for ${paramCustomerName} by the outbound`,
    );
  },
};
```

## 4. Start local dev session for your Workers

In separate terminals, start a local dev session for each of your Workers.

For your dispatcher Worker:

```sh
cd dispatch-worker
npx wrangler@dispatch-namespaces-dev dev --port 8600
```

For your outbound Worker:

```sh
cd outbound-worker
npx wrangler@dispatch-namespaces-dev dev --port 8601
```

And for your user Worker:

```sh
cd customer-worker-1
npx wrangler@dispatch-namespaces-dev dev --port 8602
```

## 5. Test your requests

Send a request to your dispatcher Worker:

```sh
curl http://localhost:8600
```

```sh
# -> user worker got "intercepted a request for customer-1 by the outbound" from fetch
```
