REST API & How It Will Improve WordPress
As applications evolve, the architecture that enables them to work with a variety of different components must change. WordPress has traditionally been driven by a core structure, which is what has given it the ability to be as modular as it is.
While this has been great for a long time, WordPress now powers more than 60 million websites. It is no longer enough that WordPress can drive simple blogs and websites. It must be capable of accepting customized calls from on-site and off-site pages.
The REST API represents an HTML-based solution to this need. It enables users to call any of WordPress’s functions through JSON-style information structures.
What is REST API?
REST API represents a type of programming structure designed to be easy-to-use and advantageous to webmasters.
It delivers six unique features:
- Uniform Interface – Information should always utilize the same type of structure. This maximizes long-term compatibility.
- Statelessness – Information should be available regardless of the state the program is in.
- Cacheable – This minimizes performance overhead, which in turn saves resources.
- Client-Server Communication – Communication will always occur in a client-server interface. This allows the client’s privileges to be defined.
- Layered System – New functions should be backwards compatible with older calls.
- Code on Demand – Clients should be able to download code, such as WYSIWYG interfaces, to temporarily extend their functionality.
The overall result of REST API is a more unified and webmaster-friendly approach to creating applications.
What is REST API as Far as WordPress is Concerned?
While the features of REST API may seem relatively generic from a general point of view, they represent one of the greatest advancements in WordPress. Everything from administrating WordPress to retrieving information about your pages will be easier due to the way REST API is implemented.
Consider a webmaster who is designing a plugin to pull the pages from a category of a WordPress site. He would normally need to work with the Index core files in PHP to pull these pages, or to work with database queries directly.
These can become problematic, as updates to WordPress may make responses unpredictable. It also allows for vulnerabilities to be created, which in turn makes WordPress significantly less secure than it should be.
REST API aims to make WordPress more secure, more reliable, increase performance and further ways WordPress can be extended. This will result in plugins that can do more, last longer, and work more reliably.
The ability to interface with more than just PHP programs is another feature that the REST API will bring. This will allow developers to create applications in Ruby, Perl, C++, and any other language capable of interpreting JSON data structures. This will be particularly useful for the development of mobile computing and the Internet of Things.
The last major effect that REST API will have on WordPress is a general improvement to its core functions. It marks the transition from a mere platform to an actual architecture that is capable of accommodating everything from traditional website to e-commerce and web 2.0 sites.
What is the Status of REST API Being Rolled Into WordPress’ Core?
The REST API for WordPress currently works, but it does not offer a full range of features. Many of these features are limited to more basic needs.
As of writing this, the REST API for WordPress includes:
- Basic endpoint functionality
- Permission callbacks and some argument sanitization
- JSON-compatible schemas
- Logical endpoints for function calls
This means that items such as the following are still in the developmental stages:
- Links that point to collections
- Auto-validation for schemas and other data calls
- Per-user access for the entire API rather than just certain functions
- Public access to readable data such as author information
How Is REST API Replacing XML-RPC?
XML-RPC has been the standard that WordPress has used for a number of years. It is a protocol that has been limited to older methods of thinking, which in turn has limited how usable it is for web applications.
When you compare a call to the REST API with an XML-RPC call, you will notice the following things:
REST API calls look more readable, tend to be more dependable and have predictable semantics.
Endpoints for REST API are easier to design. This means developing endpoints for plugins will be easier and more versatile.
Future changes to how methods will be handled are easier to predict with REST API due to the semantics involved. This allows the server to worry about any actions required to “tidy” an action.
REST API calls exist as a more human-oriented approach for HTTP-based interaction. The full implementation of a REST API in WordPress will make the platform more robust, more useful for others, and help to future-proof and secure the parts of WordPress that tend to cause issues for webmasters.