How to Cache Openweathermap API Responses at Edge
Edge TTL shield for Frontend / Web OpenWeather calls
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.
Uncached OpenWeather spikes cost and latency
Every Frontend / Web visitor can trigger a fresh OpenWeather call. Bursts exhaust per-minute quotas even when data changes slowly.
- Thundering herds after cache expiry on the origin
- Analytics skewed by client-side retry storms
- Support tickets blaming "API downtime" during spikes
How RealComposer Solves This at the Edge
Bind vault keys to the Worker
Store OPENWEATHER_API_KEY in the vault. Frontend / Web never embeds the raw secret, only a revocable rc_live_ client token.
Target the real upstream URL
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.
Call from Frontend / Web
Call https://realcomposer.com/v1/workspace/cache-weather-api-edge with a restricted rc_live_ client token. Frontend / Web never sends upstream secrets.
const res = await fetch('https://realcomposer.com/v1/workspace/cache-weather-api-edge', {
headers: { Authorization: 'Bearer rc_live_your_token' }
});
{
"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"
}
}
}
{
"temp": "sample",
"city": "sample"
}
Recipe Specs
- HTTP method
- GET
- Upstream calls
- 1
- Edge cache TTL
- 600s
- Client auth
- Restricted client token
- Mapped output fields
- 2
- Payload
- 241 B to 33 B (-86%)
curl -X GET "https://realcomposer.com/v1/workspace/cache-weather-api-edge" \ -H "Authorization: Bearer rc_live_client_token"
Developer Questions & Troubleshooting
Does Frontend / Web need CORS changes after adding RealComposer?
Use scoped tokens where the vendor allows them on cache-weather-api-edge. Admin keys stay {{secrets.*}} references only.
When does edge caching apply to this recipe?
Cache key for cache-weather-api-edge: internal edge-cache path plus sorted query. Identical params hit; vary userId per user.
What happens if an upstream step times out?
Rotate vault secrets for cache-weather-api-edge anytime; clients keep the same rc_live_ token.
Sources & Definitions Used in This Answer
Deploy this Frontend / Web + OpenWeather Recipe
Clone this pre-configured pipeline into your RealComposer workspace in one click. We pre-populate upstream URLs, headers, and mapping rules.