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

# Read a private silo from your backend

> Keep your Access Key on the server and expose only the data your front end needs.

A private silo needs an Access Key on every request. If you put that key in front-end code, anyone can read it from the browser and use it against all of your private silos. Instead, read the silo from your own server and let your front end call that server.

```text theme={null}
Browser  ──▶  Your server (holds X-SILO-KEY)  ──▶  JSONsilo private silo
```

**You will use:** a [private silo](https://docs.jsonsilo.com/silo-types/private-silo.md) and an [Access Key](https://docs.jsonsilo.com/keys/access-keys.md).

## The data

The examples use a **Private** silo named `team` with this JSON:

```json team.json theme={null}
[
  { "id": 1, "name": "Aiko Tanaka", "role": "Engineering", "status": "active" },
  { "id": 2, "name": "Sam Rivera", "role": "Design", "status": "active" },
  { "id": 3, "name": "Noor Haddad", "role": "Support", "status": "on-leave" }
]
```

## 1. Store the key and URL as environment variables

```bash .env theme={null}
JSONSILO_URL=https://[region-code].jsonsilo.com/[file-uuid]
JSONSILO_ACCESS_KEY=<YOUR_X_SILO_KEY_HERE>
```

> [!WARNING]
>
> Add `.env` to your `.gitignore`. In production, use your host's secret settings instead of a file.

## 2. Add a route that reads the silo

Each example exposes `GET /api/team`, which returns the silo's data. It forwards JSONsilo's status code when the request fails, so a `404` or `429` reaches your logs unchanged.

> [tab] Next.js
>
> A [route handler](https://nextjs.org/docs/app/building-your-application/routing/route-handlers) in the App Router. It runs on the server, so the key never reaches the browser.
>
> ```javascript app/api/team/route.js theme={null}
> export async function GET() {
>   const res = await fetch(process.env.JSONSILO_URL, {
>     headers: { 'X-SILO-KEY': process.env.JSONSILO_ACCESS_KEY },
>     next: { revalidate: 60 }, // reuse the result for 60 seconds
>   });
>
>   if (!res.ok) {
>     return Response.json({ error: 'Could not load team' }, { status: res.status });
>   }
>
>   return Response.json(await res.json());
> }
> ```
>
> Or read it directly in a Server Component:
>
> ```jsx app/team/page.jsx theme={null}
> export default async function TeamPage() {
>   const res = await fetch(process.env.JSONSILO_URL, {
>     headers: { 'X-SILO-KEY': process.env.JSONSILO_ACCESS_KEY },
>     next: { revalidate: 60 },
>   });
>   const team = await res.json();
>
>   return (
>     <ul>
>       {team.map((person) => (
>         <li key={person.id}>{person.name}</li>
>       ))}
>     </ul>
>   );
> }
> ```

> [tab] Express
>
> Node.js 18 or later has `fetch` built in.
>
> ```javascript server.js theme={null}
> import express from 'express';
>
> const app = express();
>
> app.get('/api/team', async (req, res) => {
>   try {
>     const upstream = await fetch(process.env.JSONSILO_URL, {
>       headers: { 'X-SILO-KEY': process.env.JSONSILO_ACCESS_KEY },
>     });
>
>     if (!upstream.ok) {
>       return res.status(upstream.status).json({ error: 'Could not load team' });
>     }
>
>     res.json(await upstream.json());
>   } catch (err) {
>     res.status(502).json({ error: 'JSONsilo unreachable' });
>   }
> });
>
> app.listen(3000, () => console.log('Listening on http://localhost:3000'));
> ```

> [tab] Flask
>
> ```python app.py theme={null}
> import os
>
> import requests
> from flask import Flask, jsonify
>
> app = Flask(__name__)
>
> SILO_URL = os.environ["JSONSILO_URL"]
> ACCESS_KEY = os.environ["JSONSILO_ACCESS_KEY"]
>
>
> @app.get("/api/team")
> def team():
>     try:
>         res = requests.get(SILO_URL, headers={"X-SILO-KEY": ACCESS_KEY}, timeout=5)
>     except requests.RequestException:
>         return jsonify(error="JSONsilo unreachable"), 502
>
>     if not res.ok:
>         return jsonify(error="Could not load team"), res.status_code
>
>     return jsonify(res.json())
> ```

## 3. Call your route from the front end

```javascript theme={null}
const team = await fetch('/api/team').then((res) => res.json());
```

No key is involved, so this is safe to ship to the browser.

## Return only what the page needs

Your route can pass [Query](https://docs.jsonsilo.com/features/query-silo-data.md) and [Search](https://docs.jsonsilo.com/features/search-silo-data.md) parameters through to the silo, so the browser gets a smaller response. For example, to return only active team members:

```javascript theme={null}
const url = new URL(process.env.JSONSILO_URL);
url.searchParams.set('q', 'status');
url.searchParams.set('value', 'active');

const res = await fetch(url, {
  headers: { 'X-SILO-KEY': process.env.JSONSILO_ACCESS_KEY },
});
```

> [!WARNING]
>
> Don't forward the browser's query string to JSONsilo as-is. Build the parameters yourself, so a visitor can't read fields you didn't mean to expose.

See [Product catalog with Query and Search](https://docs.jsonsilo.com/examples/product-catalog.md) for more recipes.

## Errors to handle

| Status | Likely cause |
| - | - |
| `403` | The `X-SILO-KEY` header is missing. Check that the environment variable is set. |
| `401` | The Access Key is wrong or was deleted. |
| `404` | Wrong UUID or region, or the silo was made public (its URL changed). |
| `429` | You hit a [rate limit](https://docs.jsonsilo.com/rate-limits.md). Cache results on your server to send fewer requests. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.