- Learning WordPress REST API
- Sufyan bin Uzayr
- 755字
- 2021-07-14 11:00:48
REST API in WordPress
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.
Universality
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.
Remote management
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.
Note
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.
Third-party support
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.
- 從零構(gòu)建知識(shí)圖譜:技術(shù)、方法與案例
- Java多線(xiàn)程編程實(shí)戰(zhàn)指南:設(shè)計(jì)模式篇(第2版)
- JIRA 7 Administration Cookbook(Second Edition)
- ASP.NET Core Essentials
- 精通搜索分析
- Python爬蟲(chóng)開(kāi)發(fā)與項(xiàng)目實(shí)戰(zhàn)
- 你必須知道的204個(gè)Visual C++開(kāi)發(fā)問(wèn)題
- Java EE 7 Development with NetBeans 8
- FFmpeg入門(mén)詳解:音視頻原理及應(yīng)用
- C語(yǔ)言程序設(shè)計(jì)實(shí)驗(yàn)指導(dǎo) (第2版)
- ASP.NET程序開(kāi)發(fā)范例寶典
- Java并發(fā)編程之美
- Python Deep Learning
- Web開(kāi)發(fā)的平民英雄:PHP+MySQL
- Visual Basic程序設(shè)計(jì)基礎(chǔ)