{
  "slug": "cache-third-party-api-at-edge",
  "title": "How to Cache Third Party API at The Edge with Cloudflare",
  "metaTitle": "Cache Third Party API at The Edge - RealComposer",
  "metaDescription": "How to cache third party api at the edge with cloudflare. Shield REST API with 300s GET edge cache; cache key uses query params on.",
  "headline": "Edge TTL shield for Frontend / Web REST API calls",
  "category": "caching",
  "categoryLabel": "Edge Caching & Rate Limits",
  "urgency": 9,
  "clientPlatform": "Frontend / Web",
  "upstreamServices": [
    "REST API"
  ],
  "searchIntentQuery": "how to cache third party api at the edge with cloudflare",
  "directAnswerSummary": "To how to cache third party api at the edge with cloudflare, set cacheTtlSeconds on a GET pipeline targeting https://jsonplaceholder.typicode.com/users/{{query.userId}}. Identical query strings reuse Cloudflare caches.default before upstream sees traffic.",
  "problem": {
    "title": "Uncached REST API spikes cost and latency",
    "explanation": "Every Frontend / Web visitor can trigger a fresh REST API call. Bursts exhaust per-minute quotas even when data changes slowly.",
    "risks": [
      "Thundering herds after cache expiry on the origin",
      "Analytics skewed by client-side retry storms",
      "Support tickets blaming \"API downtime\" during spikes"
    ]
  },
  "solutionSteps": [
    {
      "stepNumber": 1,
      "title": "Bind vault keys to the Worker",
      "description": "Add API_BEARER_TOKEN to RealComposer Secret Vault. Values decrypt only inside the Cloudflare Worker that calls the upstream."
    },
    {
      "stepNumber": 2,
      "title": "Target the real upstream URL",
      "description": "Point step upstream at https://jsonplaceholder.typicode.com/users/{{query.userId}} with GET. Add output mapping fields that mirror the JSON contract your screen already expects. Set cache TTL to 300s so repeat GETs with the same query string hit caches.default."
    },
    {
      "stepNumber": 3,
      "title": "Call from Frontend / Web",
      "description": "Call https://realcomposer.com/v1/workspace/cache-third-party-api-at-edge with a restricted rc_live_ client token. Frontend / Web never sends upstream secrets.",
      "codeSnippet": "const res = await fetch('https://realcomposer.com/v1/workspace/cache-third-party-api-at-edge', {\n  headers: { Authorization: 'Bearer rc_live_your_token' }\n});"
    }
  ],
  "pipelineConfig": {
    "name": "How to Cache Third Party API at The Edge with Cloudflare",
    "method": "GET",
    "cacheTtlSeconds": 300,
    "authMode": "client_token",
    "steps": [
      {
        "stepKey": "upstream",
        "upstreamUrlTemplate": "https://jsonplaceholder.typicode.com/users/{{query.userId}}",
        "httpMethod": "GET",
        "headersTemplate": {
          "Authorization": "Bearer {{secrets.API_BEARER_TOKEN}}"
        },
        "timeoutMs": 3000
      }
    ],
    "outputMapping": {
      "version": 1,
      "fields": [
        {
          "targetPath": "userId",
          "sourcePath": "id",
          "type": "number",
          "sourceStep": "upstream"
        },
        {
          "targetPath": "name",
          "sourcePath": "name",
          "type": "string",
          "sourceStep": "upstream"
        },
        {
          "targetPath": "email",
          "sourcePath": "email",
          "type": "string",
          "sourceStep": "upstream"
        }
      ]
    }
  },
  "sampleBloatedInput": {
    "requestId": "req_cache-th",
    "upstreamLatencyMs": 142,
    "audit": {
      "region": "edge",
      "trace": "cache-third-party-api-at-edge"
    },
    "payload": {
      "id": "sample_id",
      "status": "active",
      "nested": {
        "tags": [
          "demo"
        ],
        "internal": true
      },
      "unused_blob": {
        "foo": "bar",
        "bar": "baz"
      }
    }
  },
  "sampleSlimmedOutput": {
    "userId": "sample",
    "name": "sample",
    "email": "sample"
  },
  "curlSnippet": "curl -X GET \"https://realcomposer.com/v1/workspace/cache-third-party-api-at-edge\" \\\n  -H \"Authorization: Bearer rc_live_client_token\"",
  "faqs": [
    {
      "question": "Can Frontend / Web call REST API without holding the production key?",
      "answer": "Store API_BEARER_TOKEN for cache-third-party-api-at-edge. Frontend / Web never sees decrypted values."
    },
    {
      "question": "Does POST traffic get cached?",
      "answer": "cache-third-party-api-at-edge: only GET requests cache (300s on caches.default). Key is workspace slug plus sorted query params, not Authorization."
    },
    {
      "question": "What happens if an upstream step times out?",
      "answer": "Rotate vault secrets for cache-third-party-api-at-edge anytime; clients keep the same rc_live_ token."
    }
  ],
  "relatedRecipeSlugs": [
    "shopify-admin-api-frontend-proxy",
    "call-private-api-from-webflow-securely",
    "connect-stripe-to-retool-securely"
  ],
  "updatedAt": "2026-11-20",
  "links": {
    "page": "https://realcomposer.com/recipes/cache-third-party-api-at-edge",
    "markdown": "https://realcomposer.com/recipes/cache-third-party-api-at-edge.md",
    "json": "https://realcomposer.com/recipes/cache-third-party-api-at-edge.json",
    "install": "https://realcomposer.com/dashboard/pipelines/new?recipe=cache-third-party-api-at-edge&via=agent"
  }
}