Gutenberg: Add block data to REST API (post) response data

Created on 30 Jan 2018  路  5Comments  路  Source: WordPress/gutenberg

Issue Overview

Consider adding Gutenberg block data to the post endpoints - so when retrieving a post via the REST API you could get the block data as part of the content object.

This provides a way to get the data/content of each block of a Gutenberg-built page from the front end. This would be very useful for building component based front ends, because the components could map one-to-one with gutenberg blocks. With these endpoints, an App could easily get the data it needs to render each component. This might also provide a patch for a standard component library matching Gutenberg blocks.

POC PR for this: https://github.com/WordPress/gutenberg/pull/2649

Framework REST API Interaction [Feature] Block API [Feature] Blocks

Most helpful comment

If anyone is looking for this right now. I'm putting a PoC extension plugin together here:
https://github.com/royboy789/gutenberg-array-save

It adds both some endpoints to grab block data directly without any of the other data for the post, and adds in a new field to default /posts endpoint

All 5 comments

Noting that we want to be very clear about what is and is not capable of being parsed by the server currently. Namely, the PHP implementation of the post grammar for blocks only returns serialized block attributes, and does not return any other source'd attribute values.

Related: #4116, #2751

Even when it comes to server understanding of the blocks which exist in a post, we've granted some ability to inspect blocks via the post grammar, but early API discussions in #104 and a desire to avoid excessive data duplication led to the introduction of attribute markup sourcing which, while not technically impossible to support in PHP (e.g. via DOMDocument), I expect would not be quite as robust as a browser implementation.

https://github.com/WordPress/gutenberg/issues/4116#issuecomment-355048619

Consider adding Gutenberg block data to the post endpoints - so when retrieving a post via the REST API you could get the block data as part of the content object.

This provides a way to get the data/content of each block of a Gutenberg-built page from the front end.

Does this need to require authentication?

This should also probably be opt in somehow. Also, I think we should look at extending get_post to include another filter param called blocks: https://developer.wordpress.org/reference/functions/get_post/#parameters

If anyone is looking for this right now. I'm putting a PoC extension plugin together here:
https://github.com/royboy789/gutenberg-array-save

It adds both some endpoints to grab block data directly without any of the other data for the post, and adds in a new field to default /posts endpoint

Closing in favor of #8352. The decision on whether or not to do this will be handled on that issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jasmussen picture jasmussen  路  3Comments

ellatrix picture ellatrix  路  3Comments

franz-josef-kaiser picture franz-josef-kaiser  路  3Comments

cr101 picture cr101  路  3Comments

davidsword picture davidsword  路  3Comments