# Aggregate Weather API and Geocoding API into One Response

> Instead of Frontend / Web firing serial fetches to OpenWeather, one pipeline hits https://api.openweathermap.org/data/2.5/weather?q={{query.city}}&appid={{secrets.OPENWEATHER_API_KEY}} (and sibling steps) in parallel and returns mapped JSON.

- Canonical page: https://realcomposer.com/recipes/aggregate-weather-and-geocoding-apis
- Client platform: Frontend / Web
- Upstream services: OpenWeather
- Category: Multi-API Aggregation
- JSON version: https://realcomposer.com/recipes/aggregate-weather-and-geocoding-apis.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=aggregate-weather-and-geocoding-apis&via=agent

## Problem: Waterfall latency from multiple OpenWeather requests

Frontend / Web widgets often await OpenWeather sequentially, multiplying TLS handshakes on cellular networks and amplifying failure rates.

- Race conditions between parallel manual fetches
- Higher mobile data usage from redundant JSON
- Timeouts when any upstream exceeds cellular RTT

## Solution steps

1. **Bind vault keys to the Worker**: Add OPENWEATHER_API_KEY to RealComposer Secret Vault. Values decrypt only inside the Cloudflare Worker that calls the upstream.

2. **Set headers, mapping, and cache TTL**: 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.

3. **Call from Frontend / Web**: Authorize with Bearer rc_live_ and fetch the mapped JSON contract your UI already expects.

```
const res = await fetch('https://realcomposer.com/v1/workspace/aggregate-weather-and-geocoding-apis', {
  headers: { Authorization: 'Bearer rc_live_your_token' }
});
```

## Pipeline config

Import this config into a RealComposer pipeline. `{{secrets.NAME}}` values are read from the encrypted Secret Vault at request time, so the client never sees them.

```json
{
  "name": "Aggregate Weather API and Geocoding API into One Response",
  "method": "GET",
  "cacheTtlSeconds": 0,
  "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"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X GET "https://realcomposer.com/v1/workspace/aggregate-weather-and-geocoding-apis" \
  -H "Authorization: Bearer rc_live_client_token"
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_aggregat",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "aggregate-weather-and-geocoding-apis"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
```

Slimmed RealComposer response:

```json
{
  "temp": "sample",
  "city": "sample"
}
```

## FAQ

### What should Frontend / Web store instead of OpenWeather secrets?

Point Frontend / Web at /recipes/aggregate-weather-and-geocoding-apis edge URL. RealComposer answers OPTIONS with Access-Control headers for allowed origins.

### Will Anthropic or Linear prompt bodies be rewritten?

Cache key for aggregate-weather-and-geocoding-apis: 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 aggregate-weather-and-geocoding-apis anytime; clients keep the same rc_live_ token.
