Expose rendered blocks in REST API endpoint for Reusable Blocks #8625
Labels
[Feature] Synced Patterns
Related to synced patterns (formerly reusable blocks)
[Status] Needs More Info
Follow-up required in order to be actionable.
Milestone
I noticed an API discrepancy between REST API post endpoints and the
blocks
endpoint: the latter lacks theraw
andrendered
properties of the former. Instead, it contains a flattitle
andcontent
:gutenberg/lib/class-wp-rest-blocks-controller.php
Lines 110 to 119 in 4fd5c20
Compare with other endpoints in core for where
title
andcontent
are defined withraw
andrendered
. (Granted, thetitle
is less key to haverendered
for Reusable Blocks.)For parity with the other core endpoints, it would seem logical to include
raw
andrendered
. But also this would be very useful. Consider case of creating a reusable block and then wanting to be able to share the URL of the block for embedding on other site such as via an iframe. If there was arendered
value that used the block'srender_callback
for dynamic blocks and which appliedthe_content
filters, then you could reuse the Reusable Blocks outside of your WordPress install.Allowing the
rendered
output of a block to be exposed in the REST API could also be very useful in a site as well. Consider a case of a site that has a 10 minute TTL cache in Varnish, but there is a Latest Posts block that they want updated every minute. If the Recent Posts block were a Reusable Block and could be accessed from the REST API, then an ESI could be used to incorporate the block's contents on the edge without requiring WordPress to re-generate the entire page. This approach could also be used on the client when a service worker is installed, as it could compose a page with composite streams. It could be used to compose pages client-side using structured block templates in #3588.We'd need to be careful about permissions. We wouldn't want someone to create a Reusable Block with sensitive data in it and then have it unexpectedly exposed.
To illustrate further, if I create a Reusable Block for the Latest Posts block, there is a request to
https://example.com/wp-json/wp/v2/blocks/8145
when I open the editor, and the response is:However, I'd love to see a response instead like:
REST API endpoints originally introduced in #2503.
/cc @noisysocks
The text was updated successfully, but these errors were encountered: