Skip to content
Start here

Replace Worker Route

client.Workers.Routes.Update(ctx, routeID, params) (*RouteUpdateResponse, error)
PUT/zones/{zone_id}/workers/routes/{route_id}

Replaces the URL pattern or Worker associated with a Worker route.

Security
API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
Accepted Permissions (at least one required)
Workers Routes Write
ParametersExpand Collapse
routeID string

Identifier.

maxLength32
params RouteUpdateParams
ZoneID param.Field[string]

Path param: Identifier.

maxLength32
Pattern param.Field[string]

Body param: Pattern to match incoming requests against. Learn more.

Script param.Field[string]Optional

Body param: Name of the script to run if the route matches.

ReturnsExpand Collapse
type RouteUpdateResponse struct{…}
ID string

Identifier.

maxLength32
Pattern string

Pattern to match incoming requests against. Learn more.

Script stringOptional

Name of the script to run if the route matches.

Replace Worker Route

package main

import (
  "context"
  "fmt"

  "github.com/cloudflare/cloudflare-go"
  "github.com/cloudflare/cloudflare-go/option"
  "github.com/cloudflare/cloudflare-go/workers"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  route, err := client.Workers.Routes.Update(
    context.TODO(),
    "023e105f4ecef8ad9ca31a8372d0c353",
    workers.RouteUpdateParams{
      ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
      Pattern: cloudflare.F("example.com/*"),
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", route.ID)
}
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "id": "023e105f4ecef8ad9ca31a8372d0c353",
    "pattern": "example.com/*",
    "script": "my-workers-script"
  },
  "success": true
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "id": "023e105f4ecef8ad9ca31a8372d0c353",
    "pattern": "example.com/*",
    "script": "my-workers-script"
  },
  "success": true
}