Saotn.org now provides the WordPress REST API (WP API), for you to use my posts to fill your website. How great is that?! 🙂 But what is a REST API exactly, and what can I do with it?
The WordPress REST API is – currently – available as a plugin that allows applications to access the data produced by WordPress in JSON format. This opens up a whole new area for WordPress powered websites to share their contents, or incorperate content from others. Not to mention new possiblities in themes and plugins.
From the WP REST API website:
This plugin provides an easy to use REST API, available via HTTP. Grab your site’s data in simple JSON format, including users, posts, taxonomies and more. Retrieving or updating data is as simple as sending a HTTP request.
Want to get your site’s posts? Simply send a
/wp-json/posts. Update user with ID 4? Send a
/wp-json/users/4. Get all posts with the search term “
GET /wp-json/posts?filter[s]=awesome. It’s that easy.
WP API exposes a simple yet easy interface to WP Query, the posts API, post meta API, users API, revisions API and many more. Chances are, if you can do it with WordPress, WP API will let you do it.
For update actions you need to be authenticated of course, so you only have read/GET access on my content. A PHP example:
<?php $options = array ( 'http' => array ( 'ignore_errors' => true, ), ); $context = stream_context_create( $options ); $response = file_get_contents( 'https://www.saotn.org/wp-json/posts?type=post', false, $context ); $response = json_decode( $response ); ?>
Or to grab a specific post ID (2037):
<?php $options = array ( 'http' => array ( 'ignore_errors' => true, ), ); $context = stream_context_create( $options ); $response = file_get_contents( 'https://www.saotn.org/wp-json/posts/2037', false, $context ); $response = json_decode( $response ); ?>
Developer resources can be found here: https://developer.wordpress.com/docs/api/.
Various demo applications, plugins and articles are available for you to get more information and to build on. For example:
If you decide to let your app talk to my API URL I would appreciate a heads-up.
My name is Jan. I am not a hacker, coder, developer, programmer or guru. I am merely a system administrator, doing my daily thing at Vevida in the Netherlands. With over 15 years of experience, my specialties include Windows Server, IIS, Linux (CentOS, Debian), security, PHP, WordPress, websites & optimization. Want to support me and donate? Use this link: https://paypal.me/jreilink.
Reduce Wordfence CPU usage, disable Wordfence “Live Traffic View”
Automatically flush Redis cache after publishing a WordPress post
WordPress .htaccess security best practices in Apache 2.4.6+
Set WP_MEMORY_LIMIT value correctly in wp-config.php