venky

cd ..

Using Small API Proxies to Protect Frontend Keys

Comments
0 min

Using Small API Proxies to Protect Frontend Keys

When a tiny backend service is cleaner than exposing service credentials in a browser app.

API proxy architecture

If a provider key should not be public, the browser should not receive it. A small API proxy can keep credentials server-side while giving the frontend a narrow endpoint to call.

js
app.get("/api/rates", async (req, res) => {
  const response = await fetch(`${providerUrl}?key=${process.env.API_KEY}`);
  res.json(await response.json());
});

Keep the proxy narrow

Do not mirror the whole third-party API unless the app needs it. A focused endpoint is easier to cache, validate, rate-limit, and monitor.

Comments

Comments are not configured yet.

Support

Do you feel like supporting my work? 🙂Buymeacoffee button