{"id":30564,"date":"2020-05-04T12:03:22","date_gmt":"2020-05-04T12:03:22","guid":{"rendered":"https:\/\/www.designbombs.com\/?p=30564"},"modified":"2020-05-04T00:04:33","modified_gmt":"2020-05-04T00:04:33","slug":"exposing-wordpress-site-data-for-mobile-apps","status":"publish","type":"post","link":"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/","title":{"rendered":"Exposing WordPress site data for mobile apps"},"content":{"rendered":"<p><a href=\"https:\/\/wordpress.org\">WordPress<\/a> is a <a href=\"https:\/\/www.designbombs.com\/what-is-wordpress\/\">terrific Content Management System<\/a>. It is a great choice for managing online content, not just for our website, but also for other channels such as <a href=\"https:\/\/www.designbombs.com\/best-email-list-building-plugins-wordpress\/\">newsletters<\/a> and mobile apps.<\/p>\n<p>There is a problem though: the WordPress editor works with HTML, which is not always the most appropriate language to use for mobile apps. For instance, an app can provide a better user experience by playing a YouTube video in a native component for mobile, instead of parsing the embedded YouTube video from the HTML code.<\/p>\n<p>This issue can be dealt with by transforming the HTML content to metadata: given a post, extract all of its important pieces of information (all the text in its paragraphs, all the sources of its images, all the URLs of its YouTube videos, etc) and make these available to the mobile app.<\/p>\n<p>Luckily for us, <a href=\"https:\/\/wordpress.org\/gutenberg\">Gutenberg<\/a> (the not so new anymore editor for WordPress) simplifies this task, because it already organizes all the post content into blocks, which contain their own data. Then, extracting the content from the post becomes equivalent to extracting the data from each of the blocks contained in the post, which is not difficult to do.<\/p>\n<h2>Extracting block metadata<\/h2>\n<p>WordPress provides <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/parse_blocks\/\">function <code>parse_blocks<\/code><\/a> which receives the content from a post, and returns an array of the data contained in all the blocks within its content. Given a post, then, we can easily extract its metadata like this:<\/p>\n<pre><code class=\"language-php\">\/**\r\n * Return the block information from the post\r\n *\/\r\nfunction get_post_block_metadata($post)\r\n{\r\n  return parse_blocks($post-&gt;post_content);\r\n}\r\n<\/code><\/pre>\n<p>We can manipulate the data too, such as extracting all the YouTube videos from the content. To achieve this, we iterate all the blocks in the post, filter those of type <code>\"core-embed\/youtube\"<\/code>, and finally extract the <code>\"url\"<\/code> property from them:<\/p>\n<pre><code class=\"language-php\">\/**\r\n * Extract all the YouTube video URLs from all Embed YouTube video blocks inside the post\r\n *\/\r\nfunction get_youtube_videos($post)\r\n{\r\n  \/\/ Obtain the blocks from the content\r\n  $blocks = parse_blocks($post-&gt;post_content);\r\n\r\n  \/\/ Filter the Embed YouTube video blocks\r\n  $youtubeVideoBlocks = array_filter(\r\n    $blocks,\r\n    function($block) {\r\n      return $block['blockName'] == \"core-embed\/youtube\";\r\n    }\r\n  );\r\n  \r\n  \/\/ Extract the YouTube video URLs\r\n  return array_map(\r\n    function($block) {\r\n      return $block['attrs']['url'];\r\n    },\r\n    $youtubeVideoBlocks\r\n  );\r\n}\r\n<\/code><\/pre>\n<h2>Exposing the data for external consumption<\/h2>\n<p>Starting from version 4.7, WordPress can be considered a headless Content Management System, where &#8220;headless&#8221; means that the rendering of the website and its data are decoupled. WordPress was historically rendered in the server as HTML content, but since the addition of the WP REST API we can access the website&#8217;s data as a JSON object, and render this data through the tool of our choice (such as JavaScript libraries Vue and React, and others).<\/p>\n<p>Now, instead of dealing with pure HTML content, like this:<\/p>\n<pre><code class=\"language-html\">&lt;html&gt;\r\n&lt;title&gt;My blog post&lt;\/title&gt;\r\n&lt;body&gt;\r\n  &lt;p&gt;Hello world!&lt;\/p&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/code><\/pre>\n<p>We can access the data through a JSON object, like this:<\/p>\n<pre><code class=\"language-json\">{\r\n  \"title\": {\r\n    \"rendered\": \"My blog post\"\r\n  },\r\n  \"content\": {\r\n    \"rendered\": \"&lt;p&gt;Hello world!&lt;\/p&gt;\"\r\n  }\r\n}\r\n<\/code><\/pre>\n<p>Through REST, we publish endpoints (i.e. pre-defined URLs) which expose a certain content. Unless disabled, every website running WordPress 4.7 and above will have several default endpoints available, exposing common data, such as the following ones:<\/p>\n<ul>\n<li>List of posts: <a href=\"https:\/\/nextapi.getpop.org\/wp-json\/wp\/v2\/posts\/\">\/wp-json\/wp\/v2\/posts<\/a><\/li>\n<li>Single post: <a href=\"https:\/\/nextapi.getpop.org\/wp-json\/wp\/v2\/posts\/1499\/\">\/wp-json\/wp\/v2\/posts\/${post_id}<\/a><\/li>\n<\/ul>\n<p>Being in JSON format, we can fetch the website data to display it on our mobile apps. What we need to do now is to create REST endpoints to expose the block metadata from the post.<\/p>\n<p>We could do this manually, processing all the different blocks and publishing their data into 1 or several endpoints. Luckily, there is a WordPress plugin that does exactly that, so we can save the effort. Let&#8217;s learn about it next.<\/p>\n<h2>REST endpoints for block metadata<\/h2>\n<p>The WordPress plugin <a href=\"https:\/\/wordpress.org\/plugins\/block-metadata\/\">Block Metadata<\/a> (disclaimer: I am the author) makes it easy to extract and expose the metadata from all blocks inside a post, by exposing a REST endpoint to access the content:<\/p>\n<ul>\n<li>HTML content in all blocks in a single post: <a href=\"https:\/\/nextapi.getpop.org\/wp-json\/block-metadata\/v1\/data\/1499\/\">\/wp-json\/block-metadata\/v1\/data\/${post_id}<\/a><\/li>\n<\/ul>\n<p>In addition, it provides a second endpoint which converts the HTML code contained in the block into an agnostic format. The agnostic format enables the content to be used on any kind of application, including the more exceptional ones such as audio-controlled devices (like those powered by Amazon Alexa), augmented and virtual reality, a giant LED screen or a tiny Apple Watch. The endpoint is this one:<\/p>\n<ul>\n<li>Agnostic content in all blocks in a single post: <a href=\"https:\/\/nextapi.getpop.org\/wp-json\/block-metadata\/v1\/metadata\/1499\/\">\/wp-json\/block-metadata\/v1\/metadata\/${post_id}<\/a><\/li>\n<\/ul>\n<p>Let&#8217;s see an example response when <a href=\"https:\/\/nextapi.getpop.org\/wp-json\/block-metadata\/v1\/metadata\/1499\/\">extracting the metadata<\/a> from a <a href=\"https:\/\/newapi.getpop.org\/posts\/cope-with-wordpress-post-demo-containing-plenty-of-blocks\/\">typical blog post<\/a> containing paragraphs, lists, galleries of images, YouTube videos, quotes and others:<\/p>\n<pre><code class=\"language-json\">[\r\n  {\r\n    \"blockName\": \"core\\\\\/paragraph\",\r\n    \"meta\": {\r\n      \"content\": \"Lorem ipsum dolor sit amet...\"\r\n    }\r\n  },\r\n  {\r\n    \"blockName\": \"core\\\\\/image\",\r\n    \"meta\": {\r\n      \"src\": \"https:\\\\\/\\\\\/ps.w.org\\\\\/gutenberg\\\\\/assets\\\\\/banner-1544x500.jpg\"\r\n    }\r\n  },\r\n  {\r\n    \"blockName\": \"core\\\\\/paragraph\",\r\n    \"meta\": {\r\n      \"content\": \"&lt;em&gt;Etiam tempor orci eu lobortis elementum nibh tellus molestie...&lt;\\\\\/em&gt;\"\r\n    }\r\n  },\r\n  {\r\n    \"blockName\": \"core-embed\\\\\/youtube\",\r\n    \"meta\": {\r\n      \"url\": \"https:\\\\\/\\\\\/www.youtube.com\\\\\/watch?v=9pT-q0SSYow\",\r\n      \"caption\": \"&lt;strong&gt;This is the video caption&lt;\\\\\/strong&gt;\"\r\n    }\r\n  },\r\n  {\r\n    \"blockName\": \"core\\\\\/quote\",\r\n    \"meta\": {\r\n      \"quote\": \"Saramago sonogo\\nEn la lista del longo\",\r\n      \"cite\": \"&lt;em&gt;alguno&lt;\\\\\/em&gt;\"\r\n    }\r\n  },\r\n  {\r\n    \"blockName\": \"core\\\\\/image\",\r\n    \"meta\": {\r\n      \"src\": \"https:\\\\\/\\\\\/ps.w.org\\\\\/gutenberg\\\\\/assets\\\\\/banner-1544x500.jpg\"\r\n    }\r\n  },\r\n  {\r\n    \"blockName\": \"core\\\\\/heading\",\r\n    \"meta\": {\r\n      \"size\": \"xl\",\r\n      \"heading\": \"Some heading here\"\r\n    }\r\n  },\r\n  {\r\n    \"blockName\": \"core\\\\\/gallery\",\r\n    \"meta\": {\r\n      \"imgs\": [\r\n        {\r\n          \"src\": \"https:\\\\\/\\\\\/newapi.getpop.org\\\\\/wp\\\\\/wp-content\\\\\/uploads\\\\\/2020\\\\\/01\\\\\/IMG_1250.jpg\",\r\n          \"width\": 1077,\r\n          \"height\": 808\r\n        },\r\n        {\r\n          \"src\": \"https:\\\\\/\\\\\/newapi.getpop.org\\\\\/wp\\\\\/wp-content\\\\\/uploads\\\\\/2020\\\\\/01\\\\\/IMG_1770.jpg\",\r\n          \"width\": 1077,\r\n          \"height\": 808\r\n        },\r\n        {\r\n          \"src\": \"https:\\\\\/\\\\\/newapi.getpop.org\\\\\/wp\\\\\/wp-content\\\\\/uploads\\\\\/2020\\\\\/01\\\\\/IMG_1912.jpg\",\r\n          \"width\": 1077,\r\n          \"height\": 808\r\n        }\r\n      ]\r\n    }\r\n  },\r\n  {\r\n    \"blockName\": \"core\\\\\/list\",\r\n    \"meta\": {\r\n      \"items\": [\r\n        \"First element\",\r\n        \"Second element\",\r\n        \"Third element\"\r\n      ]\r\n    }\r\n  },\r\n  {\r\n    \"blockName\": \"core\\\\\/audio\",\r\n    \"meta\": {\r\n      \"src\": false\r\n    }\r\n  },\r\n  {\r\n    \"blockName\": \"core\\\\\/paragraph\",\r\n    \"meta\": {\r\n      \"content\": \"Watch out the contrast!\"\r\n    }\r\n  },\r\n  {\r\n    \"blockName\": \"core\\\\\/file\",\r\n    \"meta\": {\r\n      \"href\": \"https:\\\\\/\\\\\/www.w3.org\\\\\/WAI\\\\\/ER\\\\\/tests\\\\\/xhtml\\\\\/testfiles\\\\\/resources\\\\\/pdf\\\\\/dummy.pdf\",\r\n      \"text\": \"Contributor-Day &lt;strong&gt;download&lt;\\\\\/strong&gt; file\"\r\n    }\r\n  },\r\n  {\r\n    \"blockName\": \"core\\\\\/code\",\r\n    \"meta\": {\r\n      \"code\": \"function recursive_parse_blocks( $content ) {\\n $ret = &amp;#91;];\\n $blocks = parse_blocks( $content );\\n recursive_add_blocks($ret, $blocks);\\n return $ret;\\n}\"\r\n    }\r\n  },\r\n  {\r\n    \"blockName\": \"core\\\\\/preformatted\",\r\n    \"meta\": {\r\n      \"text\": \"Some pre-formated text\"\r\n    }\r\n  },\r\n  {\r\n    \"blockName\": \"core\\\\\/pullquote\",\r\n    \"meta\": {\r\n      \"quote\": \"The will to win, the desire to succeed, the urge to reach your full potential\\\\u2026 these are the keys that will unlock the door to personal excellence.\",\r\n      \"cite\": \"Confucius\"\r\n    }\r\n  },\r\n  {\r\n    \"blockName\": \"core\\\\\/verse\",\r\n    \"meta\": {\r\n      \"text\": \"It is easy to hate and it is difficult to love. This is how the whole scheme of things works. All good things are difficult to achieve; and bad things are very easy to get.\"\r\n    }\r\n  }\r\n]\r\n<\/code><\/pre>\n<p>Please notice how the metadata extracted from each block is relevant to the type of block:<\/p>\n<table>\n<thead>\n<tr>\n<th>Block Type<\/th>\n<th>Metadata properties<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Paragraph<\/td>\n<td>\n<ul>\n<li>content<\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td>Image<\/td>\n<td>\n<ul>\n<li>src<\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td>YouTube video embed<\/td>\n<td>\n<ul>\n<li>url<\/li>\n<li>caption<\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td>Heading<\/td>\n<td>\n<ul>\n<li>heading<\/li>\n<li>size (<code>h1<\/code> =&gt; <code>\"xxl\"<\/code>, <code>h2<\/code> =&gt; <code>\"xl\"<\/code>, etc)<\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td>Image gallery<\/td>\n<td>\n<ul>\n<li>imgs:\n<ul>\n<li>src<\/li>\n<li>width<\/li>\n<li>height<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td>&#8230;<\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>This precise management of the data, based on their block type, provides granular control for data manipulation. For instance, we can extract only the URLs from all the YouTube videos contained in the post, and display them in the mobile app through a native video component, thus improving the user experience.<\/p>\n<h2>Extracting metadata from our own blocks<\/h2>\n<p>The plugin provides a filter <code>\"Leoloso\\BlockMetadata\\Metadata::blockMeta\"<\/code> to enable custom blocks to specify how to extract their metadata. If the property to expose is already saved as an attribute in the Gutenberg block, then it can be immediately retrieved from the <code>$block<\/code> object, under that same attribute name:<\/p>\n<pre><code class=\"language-php\">add_filter(\"Leoloso\\BlockMetadata\\Metadata::blockMeta\", \"myblock_extract_metadata\", 10, 3);\r\nfunction myblock_extract_metadata($blockMeta, $blockName, $block)\r\n{\r\n  if ($blockName == \"my-plugin\/my-block-name\") {\r\n    return [\r\n      \"attribute1\" =&gt; $block[\"attribute1\"],\r\n      \"attribute2\" =&gt; $block[\"attribute2\"]\r\n    ];\r\n  }\r\n\r\n  return $blockMeta;\r\n}\r\n<\/code><\/pre>\n<p>If the property is saved as part of the content in the block (i.e. it hasn&#8217;t been stored as an independent attribute) then we need to create a regular expression, or regex, to extract it from within the content stored under property <code>innerHTML<\/code>:<\/p>\n<pre><code class=\"language-php\">add_filter(\"Leoloso\\BlockMetadata\\Metadata::blockMeta\", \"myblock_extract_metadata\", 10, 3);\r\nfunction myblock_extract_metadata($blockMeta, $blockName, $block)\r\n{\r\n  if ($blockName == \"my-plugin\/my-block-name\") {\r\n    $matches = [];\r\n    preg_match_all('\/&lt;p&gt;(.*?)&lt;\\\/p&gt;\/', $quoteHTML, $matches)\r\n    return [\r\n      \"paragraphs\" =&gt; $matches[1],\r\n    ];\r\n  }\r\n\r\n  return $blockMeta;\r\n}\r\n<\/code><\/pre>\n<p>Then, whenever the post contains our custom block, its data will be made available in the response from the REST endpoint:<\/p>\n<pre><code class=\"language-json\">[\r\n  {\r\n    \"blockName\": \"my-plugin\\\\\/my-block-name\",\r\n    \"meta\": {\r\n      \"attribute1\": \"...\",\r\n      \"attribute2\": \"...\"\r\n    }\r\n  }\r\n]\r\n<\/code><\/pre>\n<h2>Conclusion<\/h2>\n<p>The advent of Gutenberg into WordPress has meant more than having a new interface for creating our posts: because it organizes the data through blocks, which can be processed according to their block type, we now have a powerful tool to manipulate data, with fine-grained control.<\/p>\n<p>Combining Gutenberg with the WP REST API means that we can make the website data available on any format, for any device. For instance, we can retrieve all the YouTube video URLs from the post, as to display them through a native component in our mobile app.<\/p>\n<p>Since HTML code is not always suitable for mobile apps, though, we need to first transform it to an agnostic format. We can do this task manually, or we can rely on the WordPress plugin <a href=\"https:\/\/wordpress.org\/plugins\/block-metadata\/\">Block Metadata<\/a> to do it for us, and even incorporate our own blocks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WordPress is a terrific Content Management System. It is a great choice for managing online content, not just for our&#8230;<\/p>\n","protected":false},"author":50,"featured_media":30711,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[51],"tags":[3168],"class_list":{"0":"post-30564","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-coding","8":"tag-gutenberg","9":"entry"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v18.1 (Yoast SEO v26.4) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Exposing WordPress site data for mobile apps<\/title>\n<meta name=\"description\" content=\"How to power a mobile app with WordPress content, by extracting data from the post created with Gutenberg, and exposing an endpoint with the WP REST API\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Exposing WordPress site data for mobile apps\" \/>\n<meta property=\"og:description\" content=\"WordPress is a terrific Content Management System. It is a great choice for managing online content, not just for our website, but also for other channels\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/\" \/>\n<meta property=\"og:site_name\" content=\"Design Bombs\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/designbombs\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-05-04T12:03:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/02\/exposing-site-data-mobile-apps-db.png\" \/>\n\t<meta property=\"og:image:width\" content=\"722\" \/>\n\t<meta property=\"og:image:height\" content=\"300\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Leonardo Losoviz\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@losoviz\" \/>\n<meta name=\"twitter:site\" content=\"@designbombs\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Leonardo Losoviz\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/\"},\"author\":{\"name\":\"Leonardo Losoviz\",\"@id\":\"https:\/\/www.designbombs.com\/#\/schema\/person\/4259b761dbd3ee01f8c7e2cd9d74df39\"},\"headline\":\"Exposing WordPress site data for mobile apps\",\"datePublished\":\"2020-05-04T12:03:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/\"},\"wordCount\":1024,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.designbombs.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/02\/exposing-site-data-mobile-apps-db.png\",\"keywords\":[\"gutenberg\"],\"articleSection\":[\"Coding\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/\",\"url\":\"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/\",\"name\":\"Exposing WordPress site data for mobile apps\",\"isPartOf\":{\"@id\":\"https:\/\/www.designbombs.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/02\/exposing-site-data-mobile-apps-db.png\",\"datePublished\":\"2020-05-04T12:03:22+00:00\",\"description\":\"How to power a mobile app with WordPress content, by extracting data from the post created with Gutenberg, and exposing an endpoint with the WP REST API\",\"breadcrumb\":{\"@id\":\"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/#primaryimage\",\"url\":\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/02\/exposing-site-data-mobile-apps-db.png\",\"contentUrl\":\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/02\/exposing-site-data-mobile-apps-db.png\",\"width\":722,\"height\":300,\"caption\":\"Exposing WordPress site data for mobile apps\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.designbombs.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Coding\",\"item\":\"https:\/\/www.designbombs.com\/category\/coding\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Exposing WordPress site data for mobile apps\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.designbombs.com\/#website\",\"url\":\"https:\/\/www.designbombs.com\/\",\"name\":\"Design Bombs\",\"description\":\"Droppin&#039; design bombs everyday!\",\"publisher\":{\"@id\":\"https:\/\/www.designbombs.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.designbombs.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.designbombs.com\/#organization\",\"name\":\"DesignBombs\",\"url\":\"https:\/\/www.designbombs.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.designbombs.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2019\/04\/db-logo.png\",\"contentUrl\":\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2019\/04\/db-logo.png\",\"width\":219,\"height\":92,\"caption\":\"DesignBombs\"},\"image\":{\"@id\":\"https:\/\/www.designbombs.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/designbombs\/\",\"https:\/\/x.com\/designbombs\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.designbombs.com\/#\/schema\/person\/4259b761dbd3ee01f8c7e2cd9d74df39\",\"name\":\"Leonardo Losoviz\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.designbombs.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/bb059a4470fd73113804d5dd7430f6a66aaba66ba161798d0fac79b124c74611?s=96&d=https%3A%2F%2Fwww.designbombs.com%2Fwp-content%2Fthemes%2FDesignBombs%2Fimages%2Fgravatar.jpg&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/bb059a4470fd73113804d5dd7430f6a66aaba66ba161798d0fac79b124c74611?s=96&d=https%3A%2F%2Fwww.designbombs.com%2Fwp-content%2Fthemes%2FDesignBombs%2Fimages%2Fgravatar.jpg&r=g\",\"caption\":\"Leonardo Losoviz\"},\"description\":\"Leonardo Losoviz is an open source developer and technical writer, author of GraphQL by PoP, a CMS-agnostic GraphQL server in PHP. Find him on his blog leoloso.com and on Twitter @losoviz.\",\"sameAs\":[\"https:\/\/leoloso.com\",\"https:\/\/x.com\/losoviz\"],\"url\":\"https:\/\/www.designbombs.com\/author\/leo\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Exposing WordPress site data for mobile apps","description":"How to power a mobile app with WordPress content, by extracting data from the post created with Gutenberg, and exposing an endpoint with the WP REST API","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/","og_locale":"en_US","og_type":"article","og_title":"Exposing WordPress site data for mobile apps","og_description":"WordPress is a terrific Content Management System. It is a great choice for managing online content, not just for our website, but also for other channels","og_url":"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/","og_site_name":"Design Bombs","article_publisher":"https:\/\/www.facebook.com\/designbombs\/","article_published_time":"2020-05-04T12:03:22+00:00","og_image":[{"width":722,"height":300,"url":"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/02\/exposing-site-data-mobile-apps-db.png","type":"image\/png"}],"author":"Leonardo Losoviz","twitter_card":"summary_large_image","twitter_creator":"@losoviz","twitter_site":"@designbombs","twitter_misc":{"Written by":"Leonardo Losoviz","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/#article","isPartOf":{"@id":"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/"},"author":{"name":"Leonardo Losoviz","@id":"https:\/\/www.designbombs.com\/#\/schema\/person\/4259b761dbd3ee01f8c7e2cd9d74df39"},"headline":"Exposing WordPress site data for mobile apps","datePublished":"2020-05-04T12:03:22+00:00","mainEntityOfPage":{"@id":"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/"},"wordCount":1024,"commentCount":0,"publisher":{"@id":"https:\/\/www.designbombs.com\/#organization"},"image":{"@id":"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/#primaryimage"},"thumbnailUrl":"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/02\/exposing-site-data-mobile-apps-db.png","keywords":["gutenberg"],"articleSection":["Coding"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/","url":"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/","name":"Exposing WordPress site data for mobile apps","isPartOf":{"@id":"https:\/\/www.designbombs.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/#primaryimage"},"image":{"@id":"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/#primaryimage"},"thumbnailUrl":"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/02\/exposing-site-data-mobile-apps-db.png","datePublished":"2020-05-04T12:03:22+00:00","description":"How to power a mobile app with WordPress content, by extracting data from the post created with Gutenberg, and exposing an endpoint with the WP REST API","breadcrumb":{"@id":"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/#primaryimage","url":"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/02\/exposing-site-data-mobile-apps-db.png","contentUrl":"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/02\/exposing-site-data-mobile-apps-db.png","width":722,"height":300,"caption":"Exposing WordPress site data for mobile apps"},{"@type":"BreadcrumbList","@id":"https:\/\/www.designbombs.com\/exposing-wordpress-site-data-for-mobile-apps\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.designbombs.com\/"},{"@type":"ListItem","position":2,"name":"Coding","item":"https:\/\/www.designbombs.com\/category\/coding\/"},{"@type":"ListItem","position":3,"name":"Exposing WordPress site data for mobile apps"}]},{"@type":"WebSite","@id":"https:\/\/www.designbombs.com\/#website","url":"https:\/\/www.designbombs.com\/","name":"Design Bombs","description":"Droppin&#039; design bombs everyday!","publisher":{"@id":"https:\/\/www.designbombs.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.designbombs.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.designbombs.com\/#organization","name":"DesignBombs","url":"https:\/\/www.designbombs.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.designbombs.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.designbombs.com\/wp-content\/uploads\/2019\/04\/db-logo.png","contentUrl":"https:\/\/www.designbombs.com\/wp-content\/uploads\/2019\/04\/db-logo.png","width":219,"height":92,"caption":"DesignBombs"},"image":{"@id":"https:\/\/www.designbombs.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/designbombs\/","https:\/\/x.com\/designbombs"]},{"@type":"Person","@id":"https:\/\/www.designbombs.com\/#\/schema\/person\/4259b761dbd3ee01f8c7e2cd9d74df39","name":"Leonardo Losoviz","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.designbombs.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/bb059a4470fd73113804d5dd7430f6a66aaba66ba161798d0fac79b124c74611?s=96&d=https%3A%2F%2Fwww.designbombs.com%2Fwp-content%2Fthemes%2FDesignBombs%2Fimages%2Fgravatar.jpg&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/bb059a4470fd73113804d5dd7430f6a66aaba66ba161798d0fac79b124c74611?s=96&d=https%3A%2F%2Fwww.designbombs.com%2Fwp-content%2Fthemes%2FDesignBombs%2Fimages%2Fgravatar.jpg&r=g","caption":"Leonardo Losoviz"},"description":"Leonardo Losoviz is an open source developer and technical writer, author of GraphQL by PoP, a CMS-agnostic GraphQL server in PHP. Find him on his blog leoloso.com and on Twitter @losoviz.","sameAs":["https:\/\/leoloso.com","https:\/\/x.com\/losoviz"],"url":"https:\/\/www.designbombs.com\/author\/leo\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/02\/exposing-site-data-mobile-apps-db.png","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.designbombs.com\/wp-json\/wp\/v2\/posts\/30564","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.designbombs.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.designbombs.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.designbombs.com\/wp-json\/wp\/v2\/users\/50"}],"replies":[{"embeddable":true,"href":"https:\/\/www.designbombs.com\/wp-json\/wp\/v2\/comments?post=30564"}],"version-history":[{"count":3,"href":"https:\/\/www.designbombs.com\/wp-json\/wp\/v2\/posts\/30564\/revisions"}],"predecessor-version":[{"id":30726,"href":"https:\/\/www.designbombs.com\/wp-json\/wp\/v2\/posts\/30564\/revisions\/30726"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.designbombs.com\/wp-json\/wp\/v2\/media\/30711"}],"wp:attachment":[{"href":"https:\/\/www.designbombs.com\/wp-json\/wp\/v2\/media?parent=30564"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.designbombs.com\/wp-json\/wp\/v2\/categories?post=30564"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.designbombs.com\/wp-json\/wp\/v2\/tags?post=30564"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}