Editor's Note: The WordPress REST API article was first published on January 12, 2106. It was updated on November 17, 2018.
With WordPress 4.4's adoption of a fully functioning REST API, powerful technology was included in the core code of WordPress. This addition of the REST API extended WordPress and opened up a world of opportunities for WordPress deployments.
What's an API?
API is short for Application Programming Interfaces. An API allows a developer to program automated functionality into a system.
When a human is accessing WordPress via its administrative panel, they're accessing a user interface. That is, you utilize the system through visible forms and use mouse clicks to navigate.
If you wished to program another system to perform the same functionality, it's difficult. However, Application Programming Interfaces were built for just this reason.
What's a REST API?
REST stands for Representational State Transfer. In simple terms, and with respect to API services on the web, REST simply means that you request information from a web address, and it sends information back, often in a machine-readable form. This response can then be used by other programs.
Nicely built REST APIs offer you the opportunity to request both the format of the data as well as the information requested.
REST API Examples
Here's a great example from freegeoip.net, a community-funded service that provides location data for a given domain or IP address:
Additional REST API examples:
- Where is Godaddy.com located? XML Request: https://freegeoip.net/xml/godaddy.com
- Where is Godaddy.com located? JSON Request: https://freegeoip.net/json/godaddy.com
- Where is Godaddy.com located? CSV Request: https://freegeoip.net/csv/godaddy.com
Perhaps you have a website where you want to dynamically display specific information based on the location of the visitor. You can pass the user's IP Address via the API call and then display the content meant for each location.
What's the WordPress REST API?
The WordPress REST API simply blends the the power of REST API technology with WordPress.
WordPress REST API usage examples
Why would anyone wish to use a REST API with WordPress? Here are some quick examples for using the WordPress REST API:
- Automated Posts — You have a weather tracking program that generates an alert for a tornado warning or watch. An API would enable you to program a WordPress site to automatically publish a post when an alert is triggered.
- Syndicated Posts — You have a mobile application where you wish to syndicate content, but there's more data that's included in a typical RSS feed. Perhaps you have custom event data, for example. An API would enable the mobile platform to authenticate and request the data from your WordPress server to update your mobile application.
- Authentication — You have a WordPress site, bbPress forum, BuddyPress social network, or WooCommerce e-commerce instance where all of your users are set up and configured. Perhaps you have a third-party application that you'd like to authenticate using the WordPress account. Being able to utilize the API eliminates the need to have users having multiple logins to multiple systems.
In other words, pulling information, pushing information or authenticating are all possible, programmatically, from outside your WordPress site! Eventually, core WordPress features will be accessible via the API.
This ability to push and pull data has helped WordPress become a framework and not just a content management system.
Theme and plugin developers can replace their own endpoints with the REST API endpoints in WordPress.
Depending on your development style, these endpoints can differ greatly in the method used or its location. Exposing the API for usage in themes and plugins will provide consistency for passing data via the API endpoint and removing unnecessary endpoints.
WordPress REST API plugin examples
The REST API has been around for quite some time in plugin format, so you'll already find some robust examples of use out on the web:
- Reactor — allows you to build fully functioning mobile applications with your self-hosted WordPress instance.
- Event Espresso — event registration and ticketing management for WordPress.
- Simmer — Develop recipe apps on mobile, web or alternative UIs.
Ready to dig deeper?
If you'd like to learn more about the REST API in WordPress, here are some great places where you can start your research.