> ## Documentation Index
> Fetch the complete documentation index at: https://developers.partoo.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Display Data From Partoo

> How to securely retrieve and render any Partoo data on a public website using a backend proxy with caching.

## Why Use a Backend Proxy?

* **Hide your Partoo API key** from the browser.
* **Cache responses** to improve performance and lower latency.
* **Respect Partoo rate limits** by eliminating redundant calls.
* **Centralize logging and error handling** in a single layer.

<Tip>
  If you already run an API gateway, add the proxy there to leverage its authentication, observability, and throttling features.
</Tip>

## Recommended Architecture

For public-facing features—such as **Store Locator**, **Click & Collect**. Route all Partoo traffic through a caching proxy:

```mermaid theme={null}
sequenceDiagram
    participant User as User Browser
    participant Frontend as Frontend App
    participant Proxy as Backend Proxy
    participant Cache as Cache DB
    participant Partoo as Partoo API

    User->>Frontend: Request location data
    Frontend->>Proxy: API request (no key exposed)
    Proxy->>Cache: Check for cached data
    alt Cache Hit
        Cache-->>Proxy: Return cached data
        Proxy-->>Frontend: Return cached data
        Frontend-->>User: Display results
    else Cache Miss
        Cache-->>Proxy: Cache miss
        Proxy->>Partoo: Request data with API key
        Partoo-->>Proxy: Return API response
        Proxy->>Cache: Store result in cache
        Proxy-->>Frontend: Return fresh data
        Frontend-->>User: Display results
    end
```

<Warning>
  This architecture is not limited to websites. You can also apply it to **mobile applications** (iOS and Android).
</Warning>

<Tip>
  By caching API responses in your backend, you reduce load on the Partoo API and avoid hitting rate limits.
</Tip>

See our <a href="/guides/api/getting-started/api-fundamentals/rate-limits">Rate Limiting</a> guide for details.

## Implementation Steps

<Steps>
  <Step title="Create a backend proxy">
    Expose an endpoint—e.g., `/api/partoo/data` in your server or serverless function.

    <CodeGroup>
      ```javascript Node.js (Express) theme={null}
      import express from 'express';
      import fetch from 'node-fetch';
      import cache from './cache.js'; // e.g. Redis

      const router = express.Router();

      router.get('/data', async (req, res) => {
        const cacheKey = 'partoo:data';
        const cached = await cache.get(cacheKey);

        if (cached) return res.json(JSON.parse(cached));

        const response = await fetch('https://api.partoo.co/v2/business/search', {
          headers: { Authorization: `Bearer ${process.env.PARTOO_API_KEY}` }
        });
        const data = await response.json();

        await cache.set(cacheKey, JSON.stringify(data), { EX: 300 }); // 5 min
        res.json(data);
      });

      export default router;
      ```

      ```python FastAPI theme={null}
      import os, json, aiohttp, aioredis
      from fastapi import FastAPI, HTTPException

      app = FastAPI()
      redis = aioredis.from_url("redis://localhost")

      @app.get("/api/partoo/data")
      async def get_data():
          cache_key = "partoo:data"
          if (cached := await redis.get(cache_key)):
              return json.loads(cached)

          async with aiohttp.ClientSession() as session:
              headers = {"Authorization": f"Bearer {os.getenv('PARTOO_API_KEY')}"}
              async with session.get("https://api.partoo.co/v2/business/search", headers=headers) as resp:
                  if resp.status != 200:
                      raise HTTPException(status_code=resp.status, detail=await resp.text())
                  data = await resp.json()

          await redis.set(cache_key, json.dumps(data), ex=300)
          return data
      ```
    </CodeGroup>

    <Warning>
      Never expose `PARTOO_API_KEY` in client-side code or version control.
    </Warning>
  </Step>

  <Step title="Add a caching layer">
    Select a cache store (Redis, Memcached, in-process LRU, or CDN-edge KV).\
    Set a TTL that matches how often your Partoo data changes—**5 minutes** is a safe default.

    <Check>
      After deployment, confirm a second request is served from the cache by inspecting logs or cache metrics.
    </Check>
  </Step>

  <Step title="Fetch data from the frontend">
    Call the proxy instead of Partoo directly.

    ```javascript theme={null}
    async function fetchBusinesses() {
      const res = await fetch('/api/partoo/data');
      if (!res.ok) throw new Error('Failed to load data');
      return res.json();
    }
    ```

    Render the data using your preferred framework (**React, Vue, Svelte, etc...**).
  </Step>
</Steps>
