MenuFacile2.0

Quickstart in 60 secondiDEV

Dal token alla prima request, in tre passi.

1. Genera un token

Vai sul pannello del ristorante: https://<tenant>.menufacile.it/admin/api-tokens.

Il token è una stringa tipo 12|abc...xyz (Sanctum personal access token).

2. Prima richiesta

Apri un terminale o un client REST (Postman, Insomnia, ecc.) e prova:

curl -H "Authorization: Bearer 12|abc...xyz" \
     -H "Accept: application/json" \
     https://<tenant>.menufacile.it/api/v1/menu/it

Risposta (estratto):

{
  "success": true,
  "data": {
    "settings": {
      "name": "CIP Osteria Pennuta",
      "address": "Via Roma 42, Ragusa",
      "default_locale": "it",
      "supported_locales": ["it", "en"]
    },
    "theme": {
      "primary_color": "#C0AD8A",
      "background_color": "#2B3C37",
      "font_family": "Playfair Display"
    },
    "sections": [
      {
        "id": 1,
        "name": "Antipasti",
        "menu_type": "standard",
        "items": [
          {
            "id": 1,
            "name": "Code di gambero croccante",
            "description": "Coda di gambero con salsa BBQ",
            "price": 18,
            "allergens": ["crostacei"],
            "is_recommended": false
          }
        ]
      }
    ]
  }
}

💡 Token opzionale: gli endpoint /api/v1/{menu, categories, items, restaurant, theme, allergens} sono pubblici read-only e funzionano anche senza token. Per integrare il menu sul sito di un cliente non ti serve nessun token.

3. Integra in un sito

JavaScript (vanilla)

<div id="menu"></div>
<script>
  fetch('https://<tenant>.menufacile.it/api/v1/menu/it', {
    headers: { 'Accept': 'application/json' }
  })
    .then(r => r.json())
    .then(({ data }) => {
      document.getElementById('menu').innerHTML = data.sections.map(sec => `
        <section>
          <h2>${sec.name}</h2>
          <ul>
            ${sec.items.map(item => `
              <li>
                <strong>${item.name}</strong> — €${item.price}
                ${item.description ? `<p>${item.description}</p>` : ''}
              </li>
            `).join('')}
          </ul>
        </section>
      `).join('');
    });
</script>

WordPress (functions.php)

function menufacile_render_menu($atts) {
    $atts = shortcode_atts(['tenant' => '', 'locale' => 'it'], $atts);
    $cache_key = 'mf_menu_' . $atts['tenant'] . '_' . $atts['locale'];

    $data = get_transient($cache_key);
    if (!$data) {
        $url = "https://{$atts['tenant']}.menufacile.it/api/v1/menu/{$atts['locale']}";
        $resp = wp_remote_get($url, ['headers' => ['Accept' => 'application/json']]);

        if (is_wp_error($resp)) return '<p>Menu temporaneamente non disponibile.</p>';
        $data = json_decode(wp_remote_retrieve_body($resp), true)['data'] ?? null;
        set_transient($cache_key, $data, 5 * MINUTE_IN_SECONDS); // cache 5 min
    }

    if (!$data) return '<p>Menu non disponibile.</p>';

    $html = '<div class="mf-menu">';
    foreach ($data['sections'] as $sec) {
        $html .= "<h2>" . esc_html($sec['name']) . "</h2><ul>";
        foreach ($sec['items'] as $item) {
            $html .= "<li><strong>" . esc_html($item['name']) . "</strong> — €" . esc_html($item['price']) . "</li>";
        }
        $html .= "</ul>";
    }
    return $html . '</div>';
}
add_shortcode('menufacile', 'menufacile_render_menu');

Poi nel post/pagina WordPress: [menufacile tenant="ducatarocco" locale="it"].

Cosa puoi fare adesso

Hai bisogno di aiuto?

Scrivi a info@menufacile.it.