Skip to main content

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.
If you already run an API gateway, add the proxy there to leverage its authentication, observability, and throttling features.
For public-facing features—such as Store Locator, Click & Collect. Route all Partoo traffic through a caching proxy:
This architecture is not limited to websites. You can also apply it to mobile applications (iOS and Android).
By caching API responses in your backend, you reduce load on the Partoo API and avoid hitting rate limits.
See our Rate Limiting guide for details.

Implementation Steps

1

Create a backend proxy

Expose an endpoint—e.g., /api/partoo/data in your server or serverless function.
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;
Never expose PARTOO_API_KEY in client-side code or version control.
2

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.
After deployment, confirm a second request is served from the cache by inspecting logs or cache metrics.
3

Fetch data from the frontend

Call the proxy instead of Partoo directly.
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…).