# WeWeb Call Multiple APIs on Page Load

> WeWeb pages that fetch several collections on load wait for each request and expose any keys used. A RealComposer pipeline calls Supabase and Stripe in parallel at the edge, injects both credentials from the vault, and returns one merged JSON object you bind as a single WeWeb collection.

- Canonical page: https://realcomposer.com/recipes/weweb-multiple-apis-page-load
- Client platform: WeWeb
- Upstream services: Supabase, Stripe
- Category: Multi-API Aggregation
- JSON version: https://realcomposer.com/recipes/weweb-multiple-apis-page-load.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=weweb-multiple-apis-page-load&via=agent

## Problem: Why multiple WeWeb collections slow page load

Dashboards built in WeWeb often combine a Supabase profile with Stripe billing state. Two or three collections fetched on page load add round trips on mobile networks, and the Stripe call cannot run safely from the browser at all.

- Sequential collection fetches delaying first render
- Stripe secret key needed for billing data in the front end
- Duplicate formatting logic across WeWeb formulas

## Solution steps

1. **Store credentials in Secret Vault**: Save SUPABASE_SERVICE_ROLE_KEY and STRIPE_SECRET_KEY in RealComposer so the value never enters the WeWeb project.

2. **Configure the edge pipeline**: Add the upstream steps with vault header injection, set allowed origins, and map only the fields the screen binds.

3. **Bind one WeWeb collection to the pipeline**: Call your workspace edge URL with a restricted rc_live_ client token.

```
// WeWeb REST API collection
URL:     https://realcomposer.com/v1/workspace/weweb-multiple-apis-page-load?userId={{user.id}}&customerId={{user.stripeCustomerId}}
Headers: Authorization: Bearer rc_live_client_token
Fetch:   On page load
```

## 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": "WeWeb Call Multiple APIs on Page Load",
  "method": "GET",
  "cacheTtlSeconds": 0,
  "authMode": "client_token",
  "steps": [
    {
      "stepKey": "supabase",
      "upstreamUrlTemplate": "https://{{secrets.SUPABASE_PROJECT_REF}}.supabase.co/rest/v1/profiles?id=eq.{{query.userId}}&select=full_name",
      "httpMethod": "GET",
      "headersTemplate": {
        "apikey": "{{secrets.SUPABASE_SERVICE_ROLE_KEY}}",
        "Authorization": "Bearer {{secrets.SUPABASE_SERVICE_ROLE_KEY}}"
      },
      "timeoutMs": 3000
    },
    {
      "stepKey": "stripe",
      "upstreamUrlTemplate": "https://api.stripe.com/v1/subscriptions?customer={{query.customerId}}&limit=1",
      "httpMethod": "GET",
      "headersTemplate": {
        "Authorization": "Bearer {{secrets.STRIPE_SECRET_KEY}}"
      },
      "timeoutMs": 3000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "name",
        "sourceStep": "supabase",
        "sourcePath": "0.full_name"
      },
      {
        "targetPath": "subscriptionStatus",
        "sourceStep": "stripe",
        "sourcePath": "data.0.status"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X GET "https://realcomposer.com/v1/workspace/weweb-multiple-apis-page-load" \
  -H "Authorization: Bearer rc_live_client_token"
```

## Payload before and after

Raw upstream response:

```json
{
  "supabase": [
    {
      "full_name": "Ada Lovelace"
    }
  ],
  "stripe": {
    "object": "list",
    "has_more": false,
    "data": [
      {
        "id": "sub_1Px",
        "status": "active",
        "livemode": true
      }
    ]
  }
}
```

Slimmed RealComposer response:

```json
{
  "name": "Ada Lovelace",
  "subscriptionStatus": "active"
}
```

## FAQ

### Is the Supabase service role key safe here?

Yes, because it stays in the RealComposer vault. The query is filtered to the requested user id, and only two fields return to WeWeb.

### What if Stripe is slow?

Each step has its own timeout, and the pipeline still returns the Supabase fields if the Stripe step fails, so the page renders.
