Cloudflare Link Shortener icon

Cloudflare Link Shortener

CRUD de links curtos no Workers KV. Com provisionamento automático: cria namespace, publica Worker de redirect e associa o hostname da Base da URL curta na Cloudflare.

Atualizar

AI-generated

Summary

Update an existing short link (slug) in the Cloudflare Workers KV storage, modifying its destination URL and/or active status as configured.

Inputs

  • autoProvision — Optional boolean to automatically provision infrastructure: ensures the KV namespace exists, publishes the redirect Worker, and links the hostname if using the short URL base. Requires appropriate API token permissions.
  • slug (required) — The existing short link identifier (slug) to update (e.g., 'campanha-natal').
  • newUrl — New destination URL to assign to the slug; if empty, the current stored URL remains unchanged.
  • active — Boolean to set whether the short link is active; when inactive, the Worker should respond with 404 or block, though the record stays in KV.

Output shape

a list of JSON objects, each containing the updated slug, its short URL, updated metadata fields (url, active status, creation and update timestamps, clicks), and Cloudflare API response details

Processes each input item individually; throws an error if the slug does not exist or if validation fails. The short URL is built combining the configured base URL and the slug. Infrastructure provisioning (KV namespace and Workers deployment) occurs if autoProvision is enabled.

Examples

Example 1: Updating a slug's destination URL and setting it active

Provide the slug name of the existing short link, a new destination URL as 'newUrl', and set 'active' to true. Optionally enable 'autoProvision' to ensure necessary infrastructure is in place.

Links

Discussion