APIBASE · ExemplesAPIBASE · Examples

De la configuration à la vue.
Du code complet et fonctionnel.
From config to view.
Complete working code.

Chaque exemple est autonome : configuration, lecture du schéma, requêtes de données et rendu HTML. Copiez, adaptez les accès, exécutez.

Each example is self-contained: config, schema setup, data queries, and HTML rendering. Copy, adapt credentials, run.

Les exemples sont écrits en PHP. Les mêmes appels fonctionnent dans n’importe quel langage : il suffit d’un client HTTP et d’un bearer token. Examples are written in PHP. The same calls work in any language — all you need is an HTTP client and a bearer token.
Exemple 1Example 1

Équipements et commandes associéesEquipements and their orders

Récupérer tous les équipements dont le type contient pump, puis récupérer les commandes liées à chacun et afficher le résultat dans un tableau HTML imbriqué.

Fetch all equipements where type contains pump, then for each one retrieve its orders and render the result as a nested HTML table.

C’est un fichier complet : configuration, lecture du schéma, requêtes et vue au même endroit.

This is a complete file — config, schema setup, queries, and view in one place.

Trois blocs. Config — accès et URL de base, définis une fois par environnement. Setup — appel à /schema une fois par table pour conserver les IDs T et C. View — utilisation de ces constantes pour interroger et afficher. Three blocks. Config — credentials and base URL, set once per environment. Setup — call /schema once per table, store T and C ids. View — use those constants to query and render.
// ── CONFIG ────────────────────────────────────────────────────
$api   = "https://apibase.work";
$base  = "claude";
$token = "your-token";

// ── SETUP : run once, store T and C in config ─────────────────
$eq  = api_get("$api/hive/schema/$base/equipements", $token);
$ord = api_get("$api/hive/schema/$base/orders",      $token);

$T_eq    = $eq['T'];
$eq_cols = array_flip($eq['columns']);
$C_type  = $eq_cols['type'];

$T_ord    = $ord['T'];
$ord_cols = array_flip($ord['columns']);
$C_eqid   = $ord_cols['equipement_id'];

// ── QUERY ─────────────────────────────────────────────────────
$equipements = api_get(
  "$api/hive/get/$base/T{$T_eq}/L/C{$C_type}/O28?V=pump&format=assoc",
  $token
)['data'];
<!-- VIEW ──────────────────────────────────────────────────────────── -->
<?php foreach ($equipements as $equi): ?>

  <h3><?= htmlspecialchars($equi['equipement']) ?></h3>

  <?php
    $orders = api_get(
      "$api/hive/get/$base/T{$T_ord}/L/C{$C_eqid}/O1?V={$equi['id_equipement']}&format=assoc",
      $token
    )['data'];
  ?>

  <?php if (empty($orders)): ?>
    <p>No orders.</p>
  <?php else: ?>
    <table>
      <thead>
        <tr>
          <?php foreach (array_keys($orders[0]) as $col): ?>
            <th><?= htmlspecialchars($col) ?></th>
          <?php endforeach ?>
        </tr>
      </thead>
      <tbody>
        <?php foreach ($orders as $row): ?>
          <tr>
            <?php foreach ($row as $val): ?>
              <td><?= htmlspecialchars($val) ?></td>
            <?php endforeach ?>
          </tr>
        <?php endforeach ?>
      </tbody>
    </table>
  <?php endif ?>

<?php endforeach ?>
Pourquoi les en-têtes de colonnes viennent gratuitement. format=assoc retourne les noms de colonnes comme clés de tableau. array_keys($orders[0]) vous donne la ligne d’en-tête sans coder un seul libellé en dur. Why column headers come for free. format=assoc returns column names as array keys. array_keys($orders[0]) gives you the header row without hardcoding a single label.
Exemple 2Example 2

Commandes actives avec noms de sites résolusActive orders with resolved site names

Récupérer toutes les commandes actives, extraire les IDs de sites uniques qu’elles référencent, résoudre chaque nom de site, puis afficher un tableau avec le nom au lieu de l’ID brut.

Fetch all active orders, extract the unique site ids they reference, resolve each site name, then render a table with the name displayed instead of the raw id.

// ── CONFIG ────────────────────────────────────────────────────
$api   = "https://apibase.work";
$base  = "claude";
$token = "your-token";

// ── SETUP ─────────────────────────────────────────────────────
$ord = api_get("$api/hive/schema/$base/orders", $token);
$sit = api_get("$api/hive/schema/$base/sites",  $token);

$T_ord    = $ord['T'];
$ord_cols = array_flip($ord['columns']);
$C_status = $ord_cols['status'];
$C_siteid = $ord_cols['site_id'];

$T_sit    = $sit['T'];
$sit_cols = array_flip($sit['columns']);
$C_site   = $sit_cols['site'];

// ── QUERY ─────────────────────────────────────────────────────
$orders = api_get(
  "$api/hive/get/$base/T{$T_ord}/L/C{$C_status}/O1?V=active&format=assoc",
  $token
)['data'];

// resolve site names into a lookup map
$siteIds  = array_unique(array_column($orders, 'site_id'));
$siteNames = [];
foreach ($siteIds as $id) {
  $siteNames[$id] = api_get(
    "$api/hive/get/$base/T{$T_sit}/L{$id}/C{$C_site}?format=raw",
    $token
  )['data'];
}
<!-- VIEW ──────────────────────────────────────────────────────────── -->
<table>
  <thead>
    <tr><th>Order</th><th>Client</th><th>Site</th><th>Status</th></tr>
  </thead>
  <tbody>
    <?php foreach ($orders as $row): ?>
      <tr>
        <td><?= htmlspecialchars($row['id_order'])   ?></td>
        <td><?= htmlspecialchars($row['client_id'])  ?></td>
        <td><?= htmlspecialchars($siteNames[$row['site_id']]) ?></td>
        <td><?= htmlspecialchars($row['status'])     ?></td>
      </tr>
    <?php endforeach ?>
  </tbody>
</table>
Patron de lookup map. Résolvez chaque clé étrangère unique une seule fois dans $siteNames[$id], puis utilisez cette table de correspondance dans la vue. Un appel API par site unique — pas un appel par ligne de commande. Lookup map pattern. Resolve each unique foreign key once into $siteNames[$id], then dereference in the view. One API call per unique site — not one per order row.
Exemple 3Example 3

Union inter-tables avec suivi d’origineCross-table union with origin tracking

Rechercher le même mot-clé dans trois tables — clients, contacts, fournisseurs — puis fusionner les résultats dans une seule liste. Chaque ligne est enrichie avec _type, _id et _name avant la fusion pour garder une vue uniforme peu importe l’origine.

Search the same keyword across three tables — clients, contacts, suppliers — then merge all results into a single list. Each row is tagged with _type, _id, and _name before the merge so the view stays uniform regardless of origin.

Pourquoi taguer avant la fusion ? Après array_merge, toutes les lignes sont mélangées. Sans _type, impossible de distinguer un client d’un fournisseur. Sans _id, il faut vérifier différents noms de clés primaires. Sans _name, la vue doit contenir des conditions pour chaque colonne d’affichage propre à une table. Why tag before merging? After array_merge, all rows are mixed. Without _type you cannot tell a client row from a supplier row. Without _id, you would have to check different primary key names. Without _name, the view would need conditionals for every table-specific display column.
// ── CONFIG ────────────────────────────────────────────────────
$api   = "https://apibase.work";
$base  = "claude";
$token = "your-token";

// ── SETUP ─────────────────────────────────────────────────────
$cli = api_get("$api/hive/schema/$base/clients",   $token);
$con = api_get("$api/hive/schema/$base/contacts",  $token);
$sup = api_get("$api/hive/schema/$base/suppliers", $token);

$T_clients    = $cli['T'];
$clients_cols = array_flip($cli['columns']);
$C_client     = $clients_cols['client'];

$T_contacts    = $con['T'];
$contacts_cols = array_flip($con['columns']);
$C_contact     = $contacts_cols['contact'];

$T_suppliers    = $sup['T'];
$suppliers_cols = array_flip($sup['columns']);
$C_supplier     = $suppliers_cols['supplier'];

// ── QUERY ─────────────────────────────────────────────────────
$clients = api_get(
  "$api/hive/get/$base/T{$T_clients}/L/C{$C_client}/O28?V=dupont&format=assoc",
  $token
)['data'];

$contacts = api_get(
  "$api/hive/get/$base/T{$T_contacts}/L/C{$C_contact}/O28?V=dupont&format=assoc",
  $token
)['data'];

$suppliers = api_get(
  "$api/hive/get/$base/T{$T_suppliers}/L/C{$C_supplier}/O28?V=dupont&format=assoc",
  $token
)['data'];

// ── NORMALIZE ORIGIN BEFORE MERGING ───────────────────────────
foreach ($clients as $i => $row) {
  $clients[$i]['_type'] = 'client';
  $clients[$i]['_id']   = $row['id_client'] ?? '';
  $clients[$i]['_name'] = $row['client'] ?? '';
}

foreach ($contacts as $i => $row) {
  $contacts[$i]['_type'] = 'contact';
  $contacts[$i]['_id']   = $row['id_contact'] ?? '';
  $contacts[$i]['_name'] = $row['contact'] ?? '';
}

foreach ($suppliers as $i => $row) {
  $suppliers[$i]['_type'] = 'supplier';
  $suppliers[$i]['_id']   = $row['id_supplier'] ?? '';
  $suppliers[$i]['_name'] = $row['supplier'] ?? '';
}

$all = array_merge($clients, $contacts, $suppliers);
<!-- VIEW ──────────────────────────────────────────────────────────── -->
<table>
  <thead>
    <tr><th>Type</th><th>Name</th><th>Link</th></tr>
  </thead>
  <tbody>
    <?php foreach ($all as $row): ?>
      <tr>
        <td><span class="badge"><?= htmlspecialchars($row['_type']) ?></span></td>
        <td><?= htmlspecialchars($row['_name']) ?></td>
        <td><a href="/detail/<?= htmlspecialchars($row['_type']) ?>/<?= htmlspecialchars($row['_id']) ?>">View</a></td>
      </tr>
    <?php endforeach ?>
  </tbody>
</table>
La vue est indépendante des tables. Elle lit seulement _type, _name et _id — trois clés présentes sur chaque ligne, peu importe son origine. Ajouter une quatrième table à l’union ne demande aucun changement dans la vue. The view is table-agnostic. It reads only _type, _name, and _id — three keys that exist on every row regardless of origin. Adding a fourth table to the union requires zero changes to the view.

Besoin des patrons de requêtes ?Need the query patterns?

Les exemples ci-dessus utilisent les requêtes en cascade, le filtrage multi-niveaux et l’union inter-tables. Consultez les huit patrons expliqués en détail.

The examples above use cascading, multi-level filtering, and cross-table union. See all eight patterns explained in detail.