So, now that we have seen the benefits and features of REST API and also learned a bit about JSON, how exactly can it be useful for WordPress developers?
Well, there is a lot that REST API can do in WordPress.
To begin with, the WordPress REST API is revolutionary in the sense it can help us build new applications with WordPress. Specialized editors, site management tools, and more can be created and run even without a custom API and without a companion plugin being installed on the WordPress website. As such, a WordPress theme can use the REST API to load content dynamically, and practically speaking, WordPress in itself can function as a full-fledged architectural framework.
Let us see some of the major benefits that REST API brings to the world of WordPress.
WordPress has had an API of its own for quite a while, and as such, the API part is nothing new for WordPress developers. In fact, if you have ever coded a plugin for WordPress, you might already be aware that WordPress uses its API to interact with the plugin.
However, the old WordPress API is ideal for internal processes such as a plugin, but hardly useful for external services. REST API, on the other hand, is perfect for allowing WordPress to interact with services outside of WordPress.
In other words, with REST API on board, WordPress can interact with services and websites on the Internet, which may or may not use WordPress! Yes, WordPress REST API can interact and exchange information with any service on the web that might be coded in a different language, running a different code structure, or be of a different nature.
Similarly, you can also let external services interact with WordPress content with the help of REST API. Thus, any service or website making use of REST API can now interact with your WordPress website and its posts, pages, custom post types, taxonomies, users, and more with ease, as long as it runs on the HTTP protocol (which is supported by nearly all of the Internet nowadays).
In HTTP, the POST, GET, UPDATE, and DELETE requests will allow you to create, read, update, and delete content, respectively. We shall revisit these steps with code examples in later chapters of this book, as we progress through our journey with REST API in WordPress.
WordPress REST API comes with safety measures of its own, such as cookie-based and OAuth authentication.
Cookie-based authentication is useful for plugins and themes, whereas OAuth authentication (relying on http :// oauth . net /) can be used to authenticate desktop, mobile, and web clients. This will allow WordPress REST API to define limited and clearly defined data exchange; the external service will be able to view and edit only that section of data that is made available to it, nothing else.
Notice the terms desktop, mobile, and web clients in the preceding paragraph; REST API enables remote management for WordPress. You can manage your WordPress website from a desktop client installed on your computer or a mobile application, without actually having to visit the WordPress admin panel at all!
As such, you can build clients that let you create and publish a blog using WordPress, but offer a minimal and more interactive interface than the WordPress admin panel. Since JSON is natively supported by both Android and iOS, WordPress REST API is a special boon for mobile developers who can build mobile applications that make use of REST API for interacting with WordPress platforms while running on Android or iOS.
As already stated, REST API enables WordPress to interact with services and sites that might not be built on WordPress, and vice versa. However, what can we expect from such cross-platform and third-party support?
Well, this means we can now procure content and interact with data from any other platform as long as we follow the HTTP route. For example, we can now allow Ruby on Rails (RoR) applications to interact with WordPress websites, while WordPress too can interact with systems that are otherwise not coded in PHP.
This is especially useful for folks who are working with third-party tools and need to interact with WordPress regularly. Furthermore, frontend developers can now focus on the frontend of their website without having to worry about the backend, all thanks to WordPress REST API.
Even more so, REST API can be used by WordPress developers to take their plugin and themes to non-WordPress platforms and other CMSs.