Skip to content

Commit 4d4d047

Browse files
author
Mégane Lacheny
committed
Add details and examples in new response format page
1 parent bcd8eb7 commit 4d4d047

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

docusaurus/docs/cms/migration/v4-to-v5/breaking-changes/new-response-format.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,48 @@ The Content API returns attributes of requested content without wrapping them in
9898

9999
### Notes
100100

101-
To use the Strapi v4 response format, set the following header: `Strapi-Response-Format: v4`.
101+
The `Strapi-Response-Format: v4` header temporarily restores the Strapi v4 wrapping (`data.attributes.*`). You can keep the header in place while you update each consumer, then remove it once every client can read the flattened format. The header affects REST calls, including population on relations, but does not roll back the introduction of [`documentId`](/cms/migration/v4-to-v5/breaking-changes/use-document-id).
102+
103+
To use the compatibility header while migrating:
104+
105+
1. Capture a few baseline responses before you switch the header on. These samples help you compare payloads once `attributes` comes back and ensure that relations, components, and nested populations all respond as expected.
106+
2. Add the `Strapi-Response-Format: v4` header to every REST request made by legacy clients. Remove it only after you have updated and tested each endpoint.
107+
3. Keep in mind that `documentId` continues to be the only identifier returned by the REST API when the header is absent. With the header enabled, REST responses include both `id` (for backward compatibility) and `documentId` (the canonical identifier). Plan to migrate any downstream systems that still depend on numeric `id`.
108+
109+
<details>
110+
<summary>Examples</summary>
111+
```bash title="curl"
112+
curl \
113+
-H 'Authorization: Bearer <token>' \
114+
-H 'Strapi-Response-Format: v4' \
115+
'https://api.example.com/api/articles?populate=category'
116+
```
117+
118+
```js title="fetch"
119+
await fetch('https://api.example.com/api/articles', {
120+
headers: {
121+
Authorization: `Bearer ${token}`,
122+
'Strapi-Response-Format': 'v4',
123+
},
124+
});
125+
```
126+
127+
```js title="Axios"
128+
const client = axios.create({
129+
baseURL: 'https://api.example.com/api',
130+
headers: {
131+
Authorization: `Bearer ${token}`,
132+
'Strapi-Response-Format': 'v4',
133+
},
134+
});
135+
136+
const articles = await client.get('/articles', { params: { populate: '*'} });
137+
```
138+
</details>
139+
140+
:::tip
141+
If you need to keep a mix of formats running, enable the header for any routes that still rely on `attributes`, then gradually remove it per endpoint or per consumer once you finish testing.
142+
:::
102143

103144
### Manual procedure
104145

docusaurus/static/llms-full.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9244,6 +9244,18 @@ Strapi Cloud will deploy the updated code in Strapi 5 and will automatically run
92449244

92459245
</details>
92469246

9247+
<details style={{backgroundColor: 'transparent', border: 'solid 1px #4945ff' }}>
9248+
<summary style={{fontSize: '18px'}}>How do I keep the legacy <code>attributes</code> wrapper during the migration?</summary>
9249+
9250+
- For REST clients, add the `Strapi-Response-Format: v4` header while you refactor your code. The [new response format breaking change](/cms/migration/v4-to-v5/breaking-changes/new-response-format#use-the-compatibility-header-while-migrating) shows where to add the header in `curl`, `fetch`, and Axios requests.
9251+
- For GraphQL clients, enable `v4CompatibilityMode` and follow the steps of the [GraphQL API migration documentation](/cms/migration/v4-to-v5/breaking-changes/graphql-api-updated#migration) to gradually remove `attributes`.
9252+
- REST responses continue to expose both `id` (legacy) and [`documentId`](/cms/migration/v4-to-v5/breaking-changes/use-document-id) when the header is enabled. GraphQL never exposes numeric `id`, so update your queries to use `documentId` even before you turn compatibility mode off.
9253+
9254+
Once every consumer reads the flattened format, remove the header so Strapi emits the Strapi 5 response shape by default.
9255+
<br/>
9256+
9257+
</details>
9258+
92479259

92489260

92499261
# Step-by-step guide to upgrade to Strapi 5
@@ -9338,7 +9350,7 @@ For each of them, read the indicated breaking change entry and check if some man
93389350

93399351
Strapi 5 has updated both the REST and GraphQL APIs.
93409352

9341-
Follow the steps below and leverage retro-compatibility flags and guided migration resources to gradually update your code for Strapi 5.
9353+
Follow the steps below and leverage retro-compatibility headers and guided migration resources to gradually update your code for Strapi 5.
93429354

93439355
### Migrate REST API calls
93449356

@@ -9355,7 +9367,7 @@ Follow the steps below and leverage retro-compatibility flags and guided migrati
93559367
1. Enable the compatibility header by setting `v4CompatibilityMode` to `true` in the `graphql` plugin configuration, so clients can continue to rely on `data.attributes` while you refactor them.
93569368
2. Follow each step of the [breaking change entry for GraphQL](/cms/migration/v4-to-v5/breaking-changes/graphql-api-updated). This will guide you to swap `id` for `documentId`, adopt `_connection` queries, remove `attributes`, and finally switch to `nodes/pageInfo`.
93579369
3. Test Relay and non-Relay queries by confirming that pagination metadata still matches expectations when you remove `_connection` and `data` for clients that do not need Relay semantics.
9358-
4. Disable the `v4CompatibilityMode` compatibility header: after every query and mutation works with the flattened schema, set the flag to `false` so the server emits the Strapi 5 format by default.
9370+
4. Disable the `v4CompatibilityMode` compatibility header: after every query and mutation works with the flattened schema, set the header to `false` so the server emits the Strapi 5 format by default.
93599371

93609372

93619373

0 commit comments

Comments
 (0)