Skip to content

Commit 030d107

Browse files
committed
Update the protocol
1 parent f18601f commit 030d107

File tree

1 file changed

+63
-9
lines changed

1 file changed

+63
-9
lines changed

v2/core-concepts/the-protocol.mdx

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ The very first request to an Inertia app is just a regular, full-page browser re
1010

1111
This HTML response includes the site assets (CSS, JavaScript) as well as a root `<div>` in the page's body. The root `<div>` serves as a mounting point for the client-side app, and includes a `data-page` attribute with a JSON encoded [page object](#the-page-object) for the initial page. Inertia uses this information to boot your client-side framework and display the initial page component.
1212

13-
```html
13+
```http
14+
REQUEST
15+
GET: http://example.com/events/80
16+
Accept: text/html, application/xhtml+xml
17+
18+
RESPONSE
19+
HTTP/1.1 200 OK
20+
Content-Type: text/html; charset=utf-8
21+
1422
<html>
1523
<head>
1624
<title>My app</title>
@@ -31,10 +39,24 @@ Once the Inertia app has been booted, all subsequent requests to the site are ma
3139

3240
When the server detects the `X-Inertia` header, instead of responding with a full HTML document, it returns a JSON response with an encoded [page object](#the-page-object).
3341

34-
```json
42+
```http
43+
REQUEST
44+
GET: http://example.com/events/80
45+
Accept: text/html, application/xhtml+xml
46+
X-Requested-With: XMLHttpRequest
47+
X-Inertia: true
48+
X-Inertia-Version: 6b16b94d7c51cbe5b1fa42aac98241d5
49+
50+
RESPONSE
51+
HTTP/1.1 200 OK
52+
Content-Type: application/json
53+
Vary: X-Inertia
54+
X-Inertia: true
55+
3556
{
3657
"component": "Event",
3758
"props": {
59+
"errors": {},
3860
"event": {
3961
"id": 80,
4062
"title": "Birthday party",
@@ -126,7 +148,7 @@ Inertia shares data between the server and client via a page object. This object
126148
</ParamField>
127149

128150
<ParamField body="props" type="object">
129-
The page props (data).
151+
The page props. Contains all of the page data along with an `errors` object (defaults to `{}` if there are no errors).
130152
</ParamField>
131153

132154
<ParamField body="url" type="string">
@@ -179,6 +201,7 @@ A minimal page object contains the core properties.
179201
{
180202
"component": "User/Edit",
181203
"props": {
204+
"errors": {},
182205
"user": {
183206
"name": "Jonathan"
184207
}
@@ -198,6 +221,7 @@ When using deferred props, the page object includes a `deferredProps` configurat
198221
{
199222
"component": "Posts/Index",
200223
"props": {
224+
"errors": {},
201225
"user": {
202226
"name": "Jonathan"
203227
}
@@ -226,6 +250,7 @@ When using merge props, additional configuration is included.
226250
{
227251
"component": "Feed/Index",
228252
"props": {
253+
"errors": {},
229254
"user": {
230255
"name": "Jonathan"
231256
},
@@ -277,12 +302,13 @@ When using merge props, additional configuration is included.
277302

278303
### Page Object with Scroll Props
279304

280-
When using [Infinite scroll](/v2/data-props/infinite-scroll), the page object includes a `scrollProps`configuration.
305+
When using [Infinite scroll](/v2/data-props/infinite-scroll), the page object includes a `scrollProps` configuration.
281306

282307
```json
283308
{
284309
"component": "Posts/Index",
285310
"props": {
311+
"errors": {},
286312
"posts": {
287313
"data": [
288314
{
@@ -332,26 +358,54 @@ When the Inertia client receives a `409 Conflict` response, it checks for the pr
332358

333359
If "flash" session data exists when a `409 Conflict` response occurs, Inertia's server-side framework adapters will automatically reflash this data.
334360

361+
```http
362+
REQUEST
363+
GET: http://example.com/events/80
364+
Accept: text/html, application/xhtml+xml
365+
X-Requested-With: XMLHttpRequest
366+
X-Inertia: true
367+
X-Inertia-Version: 6b16b94d7c51cbe5b1fa42aac98241d5
368+
369+
RESPONSE
370+
409: Conflict
371+
X-Inertia-Location: http://example.com/events/80
372+
```
373+
335374
You can read more about this on the [asset versioning](/v2/advanced/asset-versioning) page.
336375

337376
## Partial Reloads
338377

339378
When making Inertia requests, the partial reload option allows you to request a subset of the props (data) from the server on subsequent visits to the *same* page component. This can be a helpful performance optimization if it's acceptable that some page data becomes stale. See the [partial reloads](/v2/data-props/partial-reloads) documentation for details.
340379

341-
When a partial reload request is made, Inertia includes two additional headers with the request: `X-Inertia-Partial-Data` and `X-Inertia-Partial-Component`.
380+
When a partial reload request is made, Inertia includes the `X-Inertia-Partial-Component` header and may include `X-Inertia-Partial-Data` and/or `X-Inertia-Partial-Except` headers with the request.
342381

343382
The `X-Inertia-Partial-Data` header is a comma separated list of the desired props (data) keys that should be returned.
344383

384+
The `X-Inertia-Partial-Except` header is a comma separated list of the props (data) keys that should not be returned. When only the `X-Inertia-Partial-Except` header is included, all props (data) except those listed will be sent. If both `X-Inertia-Partial-Data` and `X-Inertia-Partial-Except` headers are included, the `X-Inertia-Partial-Except` header will take precedence.
385+
345386
The `X-Inertia-Partial-Component` header includes the name of the component that is being partially reloaded. This is necessary, since partial reloads only work for requests made to the same page component. If the final destination is different for some reason (eg. the user was logged out and is now on the login page), then no partial reloading will occur.
346387

347-
```json
388+
```http
389+
REQUEST
390+
GET: http://example.com/events
391+
Accept: text/html, application/xhtml+xml
392+
X-Requested-With: XMLHttpRequest
393+
X-Inertia: true
394+
X-Inertia-Version: 6b16b94d7c51cbe5b1fa42aac98241d5
395+
X-Inertia-Partial-Data: events
396+
X-Inertia-Partial-Component: Events
397+
398+
RESPONSE
399+
HTTP/1.1 200 OK
400+
Content-Type: application/json
401+
348402
{
349403
"component": "Events",
350404
"props": {
351-
"auth": {...},
352-
// NOT included
405+
"auth": {...}, // NOT included
353406
"categories": [...], // NOT included
354-
"events": [...] // included
407+
"events": [...], // included
408+
"errors": {} // always included
355409
},
356410
"url": "/events/80",
357411
"version": "6b16b94d7c51cbe5b1fa42aac98241d5"

0 commit comments

Comments
 (0)