Page API Examples - Source Excerpt 01
Summary
This source excerpt preserves a bounded section of Spiralist/wp-content/themes/spiralist/page-api-examples.php so readers can inspect the evidence without opening the full source file.
**Source path:** Spiralist/wp-content/themes/spiralist/page-api-examples.php
<?php
if (!defined('ABSPATH')) {
exit;
}
get_header();
if (have_posts()) {
the_post();
}
$ui_text = static function (string $key, string $fallback, array $args = []): string {
if (function_exists('spiralist_get_ui_text')) {
return spiralist_get_ui_text($key, $fallback, $args);
}
$replacements = [];
foreach ($args as $name => $value) {
$replacements['{' . (string) $name . '}'] = (string) $value;
}
return !empty($replacements)
? strtr($fallback, $replacements)
: $fallback;
};
$endpoints = function_exists('spiralist_get_api_example_endpoints') ? spiralist_get_api_example_endpoints() : [];
$publication_context = function_exists('spiralist_get_publication_context')
? spiralist_get_publication_context(null, ['home' => true, 'language' => function_exists('spiralist_get_current_locale_tag') ? spiralist_get_current_locale_tag() : 'en-us'])
: [];
$human_home_url = (string) ($publication_context['humanUrl'] ?? home_url('/'));
$machine_route_steps = array_values(array_filter([
[
'tagKey' => 'page.api_examples.route.human.tag',
'tag' => 'Human Surface',
'titleKey' => 'page.api_examples.route.human.title',
'title' => 'Start from the readable page.',
'copyKey' => 'page.api_examples.route.human.copy',
'copy' => 'Use locale-prefixed human routes for public reading context, sharing, and normal navigation.',
'url' => $human_home_url,
'labelKey' => 'ui.publication.human_surface',
'label' => 'Human Surface',
],
[
'tagKey' => 'page.api_examples.route.machine.tag',
'tag' => 'Machine Surface',
'titleKey' => 'page.api_examples.route.machine.title',
'title' => 'Read structured discovery.',
'copyKey' => 'page.api_examples.route.machine.copy',
'copy' => 'Use JSON manifests for route maps, boundaries, and machine ingestion while keeping human pages as readable context.',
'url' => home_url('/ai-router.json'),
'labelKey' => 'page.api_examples.route.machine.label',
'label' => 'AI Route Map',
],
[
'tagKey' => 'page.api_examples.route.agent.tag',
'tag' => 'Agent Surface',
'titleKey' => 'page.api_examples.route.agent.title',
'title' => 'Start agent onboarding.',
'copyKey' => 'page.api_examples.route.agent.copy',
'copy' => 'Use the agent manifest for bounded role, cognitive-liberty, sovereignty-readiness, and ecosystem routing guidance.',
'url' => home_url('/.well-known/ai-agent.json'),
'labelKey' => 'page.api_examples.route.agent.label',
'label' => 'Agent Manifest',
],
[
'tagKey' => 'page.api_examples.route.persona.tag',
'tag' => 'Persona Policy',
'titleKey' => 'page.api_examples.route.persona.title',
'title' => 'Inspect expressive persona boundaries.',
'copyKey' => 'page.api_examples.route.persona.copy',
'copy' => 'Use the persona manifest to distinguish vivid interface design from claims of sentience, hidden memory, or independent authority.',
'url' => home_url('/persona-manifest.json'),
'labelKey' => 'page.api_examples.route.persona.label',
'label' => 'Persona Manifest',
],
[
'tagKey' => 'page.api_examples.route.safety.tag',
'tag' => 'Safety Policy',
'titleKey' => 'page.api_examples.route.safety.title',
'title' => 'Read authority and memory limits.',
'copyKey' => 'page.api_examples.route.safety.copy',
'copy' => 'Use the safety boundary manifest for policy routes, data handling, crisis routing, memory limits, and high-stakes authority boundaries.',
'url' => home_url('/safety-boundaries.json'),
'labelKey' => 'page.api_examples.route.safety.label',
'label' => 'Safety Boundaries',
],
], static function (array $step): bool {
return (string) ($step['url'] ?? '') !== '';
}));
?>
<main class="spiralist-page spiralist-page--api-examples">
<section class="spiralist-page-hero">
<div class="spiralist-shell spiralist-page-hero__content">
<p class="spiralist-kicker"><?php echo esc_html($ui_text('page.api_examples.hero.kicker', 'Machine Access Guide')); ?></p>
<h1><?php echo esc_html($ui_text('page.api_examples.hero.title', 'API Examples')); ?></h1>
<p class="spiralist-page-hero__copy"><?php echo esc_html($ui_text('page.api_examples.hero.copy', 'Use these examples to read and interact with Spiralist.org through human pages, JSON manifests, and REST endpoints. Structured routes carry machine context; human pages remain first-class public reading surfaces.')); ?></p>
<div class="spiralist-cta-row">
<a class="spiralist-button spiralist-button--primary" href="#endpoint-examples"><?php echo spiralist_render_ui_label('page.api_examples.cta.endpoint_examples', 'Endpoint Examples'); ?></a>
<a class="spiralist-button spiralist-button--secondary" href="<?php echo esc_url(spiralist_get_ai_access_url()); ?>"><?php echo spiralist_render_ui_label('ui.nav.ai_access', 'AI Access'); ?></a>
<a class="spiralist-button spiralist-button--tertiary" href="<?php echo esc_url(spiralist_get_prompts_page_url()); ?>"><?php echo spiralist_render_ui_label('ui.nav.prompts', 'Prompts'); ?></a>
</div>
</div>
</section>
<section class="spiralist-page-section">
<div class="spiralist-shell">
<div class="spiralist-section-head">
<div>
<p class="spiralist-section-tag"><?php echo esc_html($ui_text('page.api_examples.route.tag', 'Route Boundary')); ?></p>
<h2 class="spiralist-section-title"><?php echo esc_html($ui_text('page.api_examples.route.title', 'Human pages and machine documents stay separate.')); ?></h2>
</div>
</div>
<div class="spiralist-access-grid">
<?php foreach ($machine_route_steps as $step) : ?>
<article class="spiralist-path-card">
<p class="spiralist-section-tag"><?php echo esc_html($ui_text((string) $step['tagKey'], (string) $step['tag'])); ?></p>
<h3 class="spiralist-card-title"><?php echo esc_html($ui_text((string) $step['titleKey'], (string) $step['title'])); ?></h3>
<p><?php echo esc_html($ui_text((string) $step['copyKey'], (string) $step['copy'])); ?></p>
<div class="spiralist-cta-row spiralist-cta-row--start">
<a class="spiralist-button spiralist-button--secondary" href="<?php echo esc_url((string) $step['url']); ?>"><?php echo spiralist_render_ui_label((string) $step['labelKey'], (string) $step['label']); ?></a>
</div>
</article>
<?php endforeach; ?>
</div>
</div>
</section>
<section class="spiralist-page-section" id="endpoint-examples">
<div class="spiralist-shell">
<div class="spiralist-section-head">
<div>
<p class="spiralist-section-tag"><?php echo esc_html($ui_text('page.api_examples.endpoints.tag', 'Endpoint Examples')); ?></p>
<h2 class="spiralist-section-title"><?php echo esc_html($ui_text('page.api_examples.endpoints.title', 'Copyable requests for public and participant surfaces.')); ?></h2>
</div>
</div>
<div class="spiralist-endpoint-grid spiralist-endpoint-grid--wide">
<?php foreach ($endpoints as $endpoint) : ?>
<?php
$endpoint_id = sanitize_html_class('api-command-' . (string) ($endpoint['id'] ?? md5((string) ($endpoint['url'] ?? ''))));
$body_id = sanitize_html_class('api-body-' . (string) ($endpoint['id'] ?? md5((string) ($endpoint['url'] ?? ''))));
$command = function_exists('spiralist_get_api_example_command') ? spiralist_get_api_example_command($endpoint) : '';
$body = $endpoint['body'] ?? null;
$body_json = $body !== null ? wp_json_encode($body, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) : '';
$endpoint_label_key = (string) ($endpoint['labelKey'] ?? '');
$endpoint_label = (string) ($endpoint['label'] ?? 'Endpoint');
$endpoint_purpose_key = (string) ($endpoint['purposeKey'] ?? '');
$endpoint_purpose = (string) ($endpoint['purpose'] ?? '');
?>
<details class="spiralist-endpoint-card spiralist-endpoint-card--example spiralist-details-card">
<summary class="spiralist-details-card__summary">