|
| 1 | +# Examples |
| 2 | + |
| 3 | +These are the canonical VDP examples. Each validates against the [VDP v0.1 schema](schema.md). |
| 4 | + |
| 5 | +## Simple View Descriptor |
| 6 | + |
| 7 | +The simplest possible view descriptor: a single template with no slots. |
| 8 | + |
| 9 | +**Use case:** A login form, a static page, or any endpoint that maps to a single template. |
| 10 | + |
| 11 | +```json title="vdp-simple.json" |
| 12 | +{ |
| 13 | + "template": "https://github.com/SiteNetSoft/quarkus-pha/templates/components/forms/form.html" |
| 14 | +} |
| 15 | +``` |
| 16 | + |
| 17 | +The server might deliver this via the `View-Template` HTTP header: |
| 18 | + |
| 19 | +```http |
| 20 | +HTTP/1.1 200 OK |
| 21 | +Content-Type: application/json |
| 22 | +View-Template: https://github.com/SiteNetSoft/quarkus-pha/templates/components/forms/form.html |
| 23 | +
|
| 24 | +{"csrfToken": "abc123", "loginUrl": "/auth/login"} |
| 25 | +``` |
| 26 | + |
| 27 | +--- |
| 28 | + |
| 29 | +## Composed View Descriptor |
| 30 | + |
| 31 | +A layout template with nested slots, forming a template tree. The sidebar layout has two slots: `sidebarNav` for navigation, and `mainContent` for a dashboard that itself contains three further slots. |
| 32 | + |
| 33 | +**Use case:** A dashboard page with a sidebar navigation, stats cards, an activity table, and a chart. |
| 34 | + |
| 35 | +```json title="vdp-composed.json" |
| 36 | +{ |
| 37 | + "template": "https://github.com/SiteNetSoft/quarkus-pha/templates/layouts/sidebar.html", |
| 38 | + "slots": { |
| 39 | + "sidebarNav": { |
| 40 | + "template": "https://github.com/SiteNetSoft/quarkus-pha/templates/components/navigation/nav.html" |
| 41 | + }, |
| 42 | + "mainContent": { |
| 43 | + "template": "https://github.com/SiteNetSoft/quarkus-pha/templates/demos/dashboard.html", |
| 44 | + "slots": { |
| 45 | + "statsCards": { |
| 46 | + "template": "https://github.com/SiteNetSoft/quarkus-pha/templates/components/data-display/card.html" |
| 47 | + }, |
| 48 | + "activityTable": { |
| 49 | + "template": "https://github.com/SiteNetSoft/quarkus-pha/templates/components/data-display/table.html" |
| 50 | + }, |
| 51 | + "revenueChart": { |
| 52 | + "template": "https://github.com/SiteNetSoft/quarkus-pha/templates/components/charts/chart.html" |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | +} |
| 58 | +``` |
| 59 | + |
| 60 | +The resulting template tree: |
| 61 | + |
| 62 | +``` |
| 63 | +sidebar.html |
| 64 | +├── sidebarNav → nav.html |
| 65 | +└── mainContent → dashboard.html |
| 66 | + ├── statsCards → card.html |
| 67 | + ├── activityTable → table.html |
| 68 | + └── revenueChart → chart.html |
| 69 | +``` |
| 70 | + |
| 71 | +This descriptor would typically be served as a standalone resource referenced via `Link` header: |
| 72 | + |
| 73 | +```http |
| 74 | +Link: <https://example.com/views/dashboard.json>; rel="view-descriptor" |
| 75 | +``` |
| 76 | + |
| 77 | +--- |
| 78 | + |
| 79 | +## Multi-View Descriptor |
| 80 | + |
| 81 | +Multiple named views for the same API response. The client selects a view based on context (device class, user preference, layout mode). |
| 82 | + |
| 83 | +**Use case:** A product page with a full detail view and a compact card view. |
| 84 | + |
| 85 | +```json title="vdp-multi-view.json" |
| 86 | +{ |
| 87 | + "views": { |
| 88 | + "default": { |
| 89 | + "template": "https://github.com/SiteNetSoft/quarkus-pha/templates/demos/dashboard.html", |
| 90 | + "slots": { |
| 91 | + "statsCards": { |
| 92 | + "template": "https://github.com/SiteNetSoft/quarkus-pha/templates/components/data-display/card.html" |
| 93 | + }, |
| 94 | + "activityTable": { |
| 95 | + "template": "https://github.com/SiteNetSoft/quarkus-pha/templates/components/data-display/table.html" |
| 96 | + } |
| 97 | + } |
| 98 | + }, |
| 99 | + "compact": { |
| 100 | + "template": "https://github.com/SiteNetSoft/quarkus-pha/templates/components/data-display/card.html" |
| 101 | + } |
| 102 | + } |
| 103 | +} |
| 104 | +``` |
| 105 | + |
| 106 | +Clients SHOULD use the `default` view when no specific view is requested. When embedded inline, use the `_views` key: |
| 107 | + |
| 108 | +```json |
| 109 | +{ |
| 110 | + "_views": { |
| 111 | + "default": { "..." : "..." }, |
| 112 | + "compact": { "..." : "..." } |
| 113 | + }, |
| 114 | + "revenue": 48200, |
| 115 | + "users": 1847 |
| 116 | +} |
| 117 | +``` |
| 118 | + |
| 119 | +--- |
| 120 | + |
| 121 | +## Slot Array |
| 122 | + |
| 123 | +A single slot accepting multiple templates rendered in sequence. Each element is a full view descriptor. |
| 124 | + |
| 125 | +**Use case:** A main content area that renders a card, chart, and table in order. |
| 126 | + |
| 127 | +```json title="vdp-slot-array.json" |
| 128 | +{ |
| 129 | + "template": "https://github.com/SiteNetSoft/quarkus-pha/templates/layouts/sidebar.html", |
| 130 | + "slots": { |
| 131 | + "mainContent": [ |
| 132 | + { |
| 133 | + "template": "https://github.com/SiteNetSoft/quarkus-pha/templates/components/data-display/card.html" |
| 134 | + }, |
| 135 | + { |
| 136 | + "template": "https://github.com/SiteNetSoft/quarkus-pha/templates/components/charts/chart.html" |
| 137 | + }, |
| 138 | + { |
| 139 | + "template": "https://github.com/SiteNetSoft/quarkus-pha/templates/components/data-display/table.html" |
| 140 | + } |
| 141 | + ], |
| 142 | + "sidebarNav": { |
| 143 | + "template": "https://github.com/SiteNetSoft/quarkus-pha/templates/components/navigation/nav.html" |
| 144 | + } |
| 145 | + } |
| 146 | +} |
| 147 | +``` |
| 148 | + |
| 149 | +The `mainContent` slot receives an array of three view descriptors. The client MUST render them in order: |
| 150 | + |
| 151 | +1. `card.html` |
| 152 | +2. `chart.html` |
| 153 | +3. `table.html` |
| 154 | + |
| 155 | +Each array element can itself contain nested `slots` for further composition. |
0 commit comments