Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add block data to REST API (post) response data #4763

Closed
adamsilverstein opened this issue Jan 30, 2018 · 5 comments
Closed

Add block data to REST API (post) response data #4763

adamsilverstein opened this issue Jan 30, 2018 · 5 comments
Labels
[Feature] Block API API that allows to express the block paradigm. [Feature] Blocks Overall functionality of blocks Framework Issues related to broader framework topics, especially as it relates to javascript REST API Interaction Related to REST API

Comments

@adamsilverstein
Copy link
Member

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: #2649

@adamsilverstein adamsilverstein added [Feature] Blocks Overall functionality of blocks REST API Interaction Related to REST API labels Jan 30, 2018
@aduth
Copy link
Member

aduth commented Jan 30, 2018

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.

#4116 (comment)

@danielbachhuber
Copy link
Member

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?

@mtias
Copy link
Member

mtias commented Jan 31, 2018

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

@mtias mtias added [Feature] Block API API that allows to express the block paradigm. Framework Issues related to broader framework topics, especially as it relates to javascript labels Jan 31, 2018
@royboy789
Copy link

royboy789 commented Apr 18, 2018

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

@danielbachhuber
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Feature] Blocks Overall functionality of blocks Framework Issues related to broader framework topics, especially as it relates to javascript REST API Interaction Related to REST API
Projects
None yet
Development

No branches or pull requests

6 participants