{
  "slug": "stale-while-revalidate-third-party-api",
  "title": "Stale While Revalidate Caching for Third Party REST Apis",
  "metaTitle": "Stale While Revalidate Caching for - RealComposer",
  "metaDescription": "Stale while revalidate caching for third party rest apis. Shield REST API with 300s GET edge cache; cache key uses query params on.",
  "headline": "REST API GET traffic cached ahead of rate limits",
  "category": "caching",
  "categoryLabel": "Edge Caching & Rate Limits",
  "urgency": 9,
  "clientPlatform": "Frontend / Web",
  "upstreamServices": [
    "REST API"
  ],
  "searchIntentQuery": "stale while revalidate caching for third party rest apis",
  "directAnswerSummary": "REST API rate limits hit fast from Frontend / Web. Cache 300s on GET calls where the query string scopes the response.",
  "problem": {
    "title": "REST API rate limits from Frontend / Web traffic",
    "explanation": "Without edge caching, identical REST API reads during a session still round-trip to the origin.",
    "risks": [
      "HTTP 429 responses during launch traffic",
      "Surprise SaaS overages from duplicate reads",
      "Slower repeat views than necessary"
    ]
  },
  "solutionSteps": [
    {
      "stepNumber": 1,
      "title": "Bind vault keys to the Worker",
      "description": "Create API_BEARER_TOKEN vault entries, then bind them to this pipeline step headers with {{secrets.NAME}} placeholders."
    },
    {
      "stepNumber": 2,
      "title": "Configure upstream steps and output mapping",
      "description": "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."
    },
    {
      "stepNumber": 3,
      "title": "Call from Frontend / Web",
      "description": "Authorize with Bearer rc_live_ and fetch the mapped JSON contract your UI already expects.",
      "codeSnippet": "const res = await fetch('https://realcomposer.com/v1/workspace/stale-while-revalidate-third-party-api', {\n  headers: { Authorization: 'Bearer rc_live_your_token' }\n});"
    }
  ],
  "pipelineConfig": {
    "name": "Stale While Revalidate Caching for Third Party REST Apis",
    "method": "GET",
    "cacheTtlSeconds": 300,
    "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_stale-wh",
    "upstreamLatencyMs": 142,
    "audit": {
      "region": "edge",
      "trace": "stale-while-revalidate-third-party-api"
    },
    "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/stale-while-revalidate-third-party-api\" \\\n  -H \"Authorization: Bearer rc_live_client_token\"",
  "faqs": [
    {
      "question": "What should Frontend / Web store instead of REST API secrets?",
      "answer": "Use scoped tokens where the vendor allows them on stale-while-revalidate-third-party-api. Admin keys stay {{secrets.*}} references only."
    },
    {
      "question": "How do I forward JSON bodies to POST upstreams?",
      "answer": "Cache key for stale-while-revalidate-third-party-api: internal edge-cache path plus sorted query. Identical params hit; vary userId per user."
    },
    {
      "question": "How do I rotate upstream credentials?",
      "answer": "Allowed origins on the stale-while-revalidate-third-party-api client token restrict which domains may call the edge URL."
    }
  ],
  "relatedRecipeSlugs": [
    "merge-airtable-and-shopify",
    "combine-stripe-customer-and-invoices",
    "stitch-two-rest-apis-flutterflow"
  ],
  "updatedAt": "2026-11-20",
  "links": {
    "page": "https://realcomposer.com/recipes/stale-while-revalidate-third-party-api",
    "markdown": "https://realcomposer.com/recipes/stale-while-revalidate-third-party-api.md",
    "json": "https://realcomposer.com/recipes/stale-while-revalidate-third-party-api.json",
    "install": "https://realcomposer.com/dashboard/pipelines/new?recipe=stale-while-revalidate-third-party-api&via=agent"
  }
}