官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 崇礼县| 中西区| 金秀| 鸡东县| 贵港市| 贡觉县| 武穴市| 肃宁县| 本溪| 兴海县| 息烽县| 兴山县| 彩票| 淳化县| 登封市| 融水| 寻乌县| 达尔| 青铜峡市| 吴忠市| 隆尧县| 大方县| 兴城市| 玉门市| 怀宁县| 竹山县| 安多县| 亳州市| 新余市| 靖西县| 新巴尔虎右旗| 峨山| 梅州市| 鱼台县| 芒康县| 隆德县| 罗源县| 兴安县| 旬邑县| 聂荣县| 福贡县|