I have been experimenting with WP-API for the last several months and here is one tip I’ve discovered so far:
I mentioned in the previous post that I needed to setup separate sub-domains for serving WP-API and consuming it.
However, I’ve been consuming WP-API as part of a theme for the same sub-domain without any problem. In fact, there are actually some benefits to use it as a WordPress theme, such as:
- The ability to use WordPress functions if you want to.
- Utilize permalink structure without implementing your own router functions or using third-party library.
- Take advantage of WordPress plugins ecosystem for the front-end.
- Can be edited using WordPress Customizer.
- And many other benefits …
Of course there are some disadvantages as well, such as slow performance of using too much plugins and use one server for both generate and process API is very resource intensive.
However, if you can’t get out of the WordPress environment just yet and still want to take advantage of WP REST API, this is the better way to go without using any third-party libraries which are not included in WordPress (it’s worth mentioning that jQuery is one of the third party libraries which is included in WordPress).
As WP REST API improves and moves more closer to the WordPress Core, we will be able to see more and more themes that use WP REST API.