{
  "slug": "optimize-api-response-size-react-native",
  "title": "How to Optimize API Response Size for React Native",
  "metaTitle": "Optimize API Response Size for - RealComposer",
  "metaDescription": "How to optimize api response size for react native. Map only UI fields from REST API before React Native parses JSON. RealComposer edge vault and client to",
  "headline": "Field-level REST API projection at the edge",
  "category": "slimmer",
  "categoryLabel": "Payload Slimmer",
  "urgency": 8,
  "clientPlatform": "React Native",
  "upstreamServices": [
    "REST API"
  ],
  "searchIntentQuery": "how to optimize api response size for react native",
  "directAnswerSummary": "REST API responses include fields React Native never renders. Map id, status, and UI columns at the edge after calling https://jsonplaceholder.typicode.com/users/{{query.userId}}.",
  "problem": {
    "title": "Unmapped REST API fields waste bandwidth",
    "explanation": "REST API returns nested CRM, audit, and configuration objects. React Native parses them on the main thread even when the UI binds three fields.",
    "risks": [
      "Large arrays kept in memory after navigation",
      "Analytics showing poor LCP on API-heavy screens",
      "Developers shipping defensive null checks for unused paths"
    ]
  },
  "solutionSteps": [
    {
      "stepNumber": 1,
      "title": "Bind vault keys to the Worker",
      "description": "Store API_BEARER_TOKEN in the vault. React Native 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://jsonplaceholder.typicode.com/users/{{query.userId}}, and Map only the UI fields in output mapping so clients never download audit or nested blobs."
    },
    {
      "stepNumber": 3,
      "title": "Call from React Native",
      "description": "Call https://realcomposer.com/v1/workspace/optimize-api-response-size-react-native with a restricted rc_live_ client token. React Native never sends upstream secrets.",
      "codeSnippet": "const res = await fetch('https://realcomposer.com/v1/workspace/optimize-api-response-size-react-native', {\n  headers: { Authorization: 'Bearer rc_live_your_token' }\n});"
    }
  ],
  "pipelineConfig": {
    "name": "How to Optimize API Response Size for React Native",
    "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"
        }
      ]
    }
  },
  "sampleBloatedInput": {
    "requestId": "req_optimize",
    "upstreamLatencyMs": 142,
    "audit": {
      "region": "edge",
      "trace": "optimize-api-response-size-react-native"
    },
    "payload": {
      "id": "sample_id",
      "status": "active",
      "nested": {
        "tags": [
          "demo"
        ],
        "internal": true
      },
      "unused_blob": {
        "foo": "bar",
        "bar": "baz"
      }
    }
  },
  "sampleSlimmedOutput": {
    "userId": "sample",
    "name": "sample",
    "email": "sample"
  },
  "curlSnippet": "curl -X GET \"https://realcomposer.com/v1/workspace/optimize-api-response-size-react-native\" \\\n  -H \"Authorization: Bearer rc_live_client_token\"",
  "faqs": [
    {
      "question": "Which REST API credential belongs in the vault for this pipeline?",
      "answer": "Yes for optimize-api-response-size-react-native. Ship only an rc_live_ client token in React Native; RealComposer injects API_BEARER_TOKEN on https://jsonplaceholder.typicode.com/users/{{query.userId}}."
    },
    {
      "question": "What cache key does RealComposer use?",
      "answer": "optimize-api-response-size-react-native vault headers attach server-side, but Anthropic or OpenAI model and messages must come from the client body."
    },
    {
      "question": "What happens if an upstream step times out?",
      "answer": "Rotate vault secrets for optimize-api-response-size-react-native anytime; clients keep the same rc_live_ token."
    }
  ],
  "relatedRecipeSlugs": [
    "reduce-third-party-api-costs-caching",
    "reverse-proxy-api-key-protection",
    "reduce-json-size-flutter-app"
  ],
  "updatedAt": "2026-11-20",
  "links": {
    "page": "https://realcomposer.com/recipes/optimize-api-response-size-react-native",
    "markdown": "https://realcomposer.com/recipes/optimize-api-response-size-react-native.md",
    "json": "https://realcomposer.com/recipes/optimize-api-response-size-react-native.json",
    "install": "https://realcomposer.com/dashboard/pipelines/new?recipe=optimize-api-response-size-react-native&via=agent"
  }
}