# Stitch Together Two REST Apis for Flutterflow

> Instead of FlutterFlow firing serial fetches to REST API, one pipeline hits https://jsonplaceholder.typicode.com/users/{{query.userId}} (and sibling steps) in parallel and returns mapped JSON.

- Canonical page: https://realcomposer.com/recipes/stitch-two-rest-apis-flutterflow
- Client platform: FlutterFlow
- Upstream services: REST API
- Category: Multi-API Aggregation
- JSON version: https://realcomposer.com/recipes/stitch-two-rest-apis-flutterflow.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=stitch-two-rest-apis-flutterflow&via=agent

## Problem: Waterfall latency from multiple REST API requests

FlutterFlow widgets often await REST API 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. **Add vault secrets for this pipeline**: Store API_BEARER_TOKEN in the vault. FlutterFlow never embeds the raw secret, only a revocable rc_live_ client token.

2. **Configure upstream steps and output mapping**: Configure headersTemplate to inject vault secrets, target https://jsonplaceholder.typicode.com/users/{{query.userId}}, and Add output mapping fields that mirror the JSON contract your screen already expects.

3. **Wire the FlutterFlow API Call**: Allowed origins on the token should list every FlutterFlow host that calls this URL.

```
// FlutterFlow API Call
URL: https://realcomposer.com/v1/workspace/stitch-two-rest-apis-flutterflow
Header 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": "Stitch Together Two REST Apis for Flutterflow",
  "method": "GET",
  "cacheTtlSeconds": 0,
  "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"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X GET "https://realcomposer.com/v1/workspace/stitch-two-rest-apis-flutterflow" \
  -H "Authorization: Bearer rc_live_client_token"
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_stitch-t",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "stitch-two-rest-apis-flutterflow"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
```

Slimmed RealComposer response:

```json
{
  "userId": "sample",
  "name": "sample",
  "email": "sample"
}
```

## FAQ

### Which REST API credential belongs in the vault for this pipeline?

Yes for stitch-two-rest-apis-flutterflow. Ship only an rc_live_ client token in FlutterFlow; RealComposer injects API_BEARER_TOKEN on https://jsonplaceholder.typicode.com/users/{{query.userId}}.

### What cache key does RealComposer use?

stitch-two-rest-apis-flutterflow POST steps bypass caches.default even if cacheTtlSeconds is set in the dashboard.

### What happens if an upstream step times out?

Upstream steps in stitch-two-rest-apis-flutterflow honor timeoutMs and optional fallback JSON without leaking secrets.
