{
  "slug": "cache-weather-api-edge",
  "title": "How to Cache Openweathermap API Responses at Edge",
  "metaTitle": "Cache Openweathermap API Responses - RealComposer",
  "metaDescription": "How to cache openweathermap api responses at edge. Shield OpenWeather with 600s GET edge cache; cache key uses query params on cache-weather-api-edge.",
  "headline": "Edge TTL shield for Frontend / Web OpenWeather calls",
  "category": "caching",
  "categoryLabel": "Edge Caching & Rate Limits",
  "urgency": 8,
  "clientPlatform": "Frontend / Web",
  "upstreamServices": [
    "OpenWeather"
  ],
  "searchIntentQuery": "how to cache openweathermap api responses at edge",
  "directAnswerSummary": "To how to cache openweathermap api responses at edge, set cacheTtlSeconds on a GET pipeline targeting https://api.openweathermap.org/data/2.5/weather?q={{query.city}}&appid={{secrets.OPENWEATHER_API_KEY}}. Identical query strings reuse Cloudflare caches.default before upstream sees traffic.",
  "problem": {
    "title": "Uncached OpenWeather spikes cost and latency",
    "explanation": "Every Frontend / Web visitor can trigger a fresh OpenWeather 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": "Store OPENWEATHER_API_KEY in the vault. Frontend / Web never embeds the raw secret, only a revocable rc_live_ client token."
    },
    {
      "stepNumber": 2,
      "title": "Target the real upstream URL",
      "description": "Configure headersTemplate to inject vault secrets, target https://api.openweathermap.org/data/2.5/weather?q={{query.city}}&appid={{secrets.OPENWEATHER_API_KEY}}, and Add output mapping fields that mirror the JSON contract your screen already expects."
    },
    {
      "stepNumber": 3,
      "title": "Call from Frontend / Web",
      "description": "Call https://realcomposer.com/v1/workspace/cache-weather-api-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-weather-api-edge', {\n  headers: { Authorization: 'Bearer rc_live_your_token' }\n});"
    }
  ],
  "pipelineConfig": {
    "name": "How to Cache Openweathermap API Responses at Edge",
    "method": "GET",
    "cacheTtlSeconds": 600,
    "authMode": "client_token",
    "steps": [
      {
        "stepKey": "weather",
        "upstreamUrlTemplate": "https://api.openweathermap.org/data/2.5/weather?q={{query.city}}&appid={{secrets.OPENWEATHER_API_KEY}}",
        "httpMethod": "GET",
        "headersTemplate": {},
        "timeoutMs": 3000
      }
    ],
    "outputMapping": {
      "version": 1,
      "fields": [
        {
          "targetPath": "temp",
          "sourcePath": "main.temp",
          "type": "number",
          "sourceStep": "weather"
        },
        {
          "targetPath": "city",
          "sourcePath": "name",
          "type": "string",
          "sourceStep": "weather"
        }
      ]
    }
  },
  "sampleBloatedInput": {
    "requestId": "req_cache-we",
    "upstreamLatencyMs": 142,
    "audit": {
      "region": "edge",
      "trace": "cache-weather-api-edge"
    },
    "payload": {
      "id": "sample_id",
      "status": "active",
      "nested": {
        "tags": [
          "demo"
        ],
        "internal": true
      },
      "unused_blob": {
        "foo": "bar",
        "bar": "baz"
      }
    }
  },
  "sampleSlimmedOutput": {
    "temp": "sample",
    "city": "sample"
  },
  "curlSnippet": "curl -X GET \"https://realcomposer.com/v1/workspace/cache-weather-api-edge\" \\\n  -H \"Authorization: Bearer rc_live_client_token\"",
  "faqs": [
    {
      "question": "Does Frontend / Web need CORS changes after adding RealComposer?",
      "answer": "Use scoped tokens where the vendor allows them on cache-weather-api-edge. Admin keys stay {{secrets.*}} references only."
    },
    {
      "question": "When does edge caching apply to this recipe?",
      "answer": "Cache key for cache-weather-api-edge: internal edge-cache path plus sorted query. Identical params hit; vary userId per user."
    },
    {
      "question": "What happens if an upstream step times out?",
      "answer": "Rotate vault secrets for cache-weather-api-edge anytime; clients keep the same rc_live_ token."
    }
  ],
  "relatedRecipeSlugs": [
    "stitch-two-rest-apis-flutterflow",
    "merge-plaid-accounts-and-transactions",
    "transform-and-rename-nested-json-keys"
  ],
  "updatedAt": "2026-11-20",
  "links": {
    "page": "https://realcomposer.com/recipes/cache-weather-api-edge",
    "markdown": "https://realcomposer.com/recipes/cache-weather-api-edge.md",
    "json": "https://realcomposer.com/recipes/cache-weather-api-edge.json",
    "install": "https://realcomposer.com/dashboard/pipelines/new?recipe=cache-weather-api-edge&via=agent"
  }
}