# Github API Response Payload Slimming for Mobile Widgets

> Answer "github api response payload slimming for mobile widgets" by projecting GitHub data server-side: upstream https://api.github.com/user/repos?per_page=5, client sees only mapped keys.

- Canonical page: https://realcomposer.com/recipes/slim-github-api-response-mobile-widgets
- Client platform: Mobile App (iOS & Android)
- Upstream services: GitHub
- Category: Payload Slimmer
- JSON version: https://realcomposer.com/recipes/slim-github-api-response-mobile-widgets.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=slim-github-api-response-mobile-widgets&via=agent

## Problem: GitHub JSON bloat on Mobile App (iOS & Android)

Oversized GitHub payloads inflate parse time and mobile data charges for Mobile App (iOS & Android) users.

- Main-thread JSON parse stalls on low-end phones
- Accidentally exposing PII fields to the client
- Downstream components re-render on unused keys

## Solution steps

1. **Add vault secrets for this pipeline**: Create GITHUB_TOKEN vault entries, then bind them to this pipeline step headers with {{secrets.NAME}} placeholders.

2. **Target the real upstream URL**: Use GET against https://api.github.com/user/repos?per_page=5. Allowed origins on the client token should match leave cache ttl at 0 when each response is user-specific (include userid or record id in query params before enabling cache).

3. **Call from Mobile App (iOS & Android)**: Allowed origins on the token should list every Mobile App (iOS & Android) host that calls this URL.

```
let url = URL(string: "https://realcomposer.com/v1/workspace/slim-github-api-response-mobile-widgets")!
var request = URLRequest(url: url)
request.addValue("Bearer rc_live_token", forHTTPHeaderField: "Authorization")
```

## 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": "Github API Response Payload Slimming for Mobile Widgets",
  "method": "GET",
  "cacheTtlSeconds": 0,
  "authMode": "client_token",
  "steps": [
    {
      "stepKey": "github",
      "upstreamUrlTemplate": "https://api.github.com/user/repos?per_page=5",
      "httpMethod": "GET",
      "headersTemplate": {
        "Authorization": "Bearer {{secrets.GITHUB_TOKEN}}",
        "Accept": "application/vnd.github+json"
      },
      "timeoutMs": 3000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "repoId",
        "sourcePath": "0.id",
        "type": "number",
        "sourceStep": "github"
      },
      {
        "targetPath": "fullName",
        "sourcePath": "0.full_name",
        "type": "string",
        "sourceStep": "github"
      },
      {
        "targetPath": "isPrivate",
        "sourcePath": "0.private",
        "type": "boolean",
        "sourceStep": "github"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X GET "https://realcomposer.com/v1/workspace/slim-github-api-response-mobile-widgets" \
  -H "Authorization: Bearer rc_live_client_token"
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_slim-git",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "slim-github-api-response-mobile-widgets"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
```

Slimmed RealComposer response:

```json
{
  "repoId": "sample",
  "fullName": "sample",
  "isPrivate": "sample"
}
```

## FAQ

### Which GitHub credential belongs in the vault for this pipeline?

Point Mobile App (iOS & Android) at /recipes/slim-github-api-response-mobile-widgets edge URL. RealComposer answers OPTIONS with Access-Control headers for allowed origins.

### Does POST traffic get cached?

Cache key for slim-github-api-response-mobile-widgets: internal edge-cache path plus sorted query. Identical params hit; vary userId per user.

### Can I restrict which domains call this pipeline?

Rotate vault secrets for slim-github-api-response-mobile-widgets anytime; clients keep the same rc_live_ token.
