If you follow WordPress news, you’ve probably heard about the REST API already. We’ve been talking about it for years, and it’s been presented as a revolution within WordPress. That’s all great, but what does it mean in practice?
The REST API is a new way to interact with a WordPress site. You can use that API to consume content from the site, or create content using something that is not your regular WordPress dashboard. This opens the door to new apps, tools, and websites.
Up until now, there were 3 ways to use the REST API:
- You could use the only route available in WordPress Core,
oEmbed, to embed WordPress posts.
- You could build on top of the Rest API infrastructure that’s already available in Core. Jetpack, for example, uses that infrastructure and creates its own custom endpoints used all over its new admin interface.
- You could rely on the REST API plugin to create default endpoints for you, and then build on top of those endpoints.
Starting in WordPress 4.7, WordPress will ship with its own default endpoints:
- Posts, allowing you to get information about any Post Type on your site;
Everyone is now able build on top of that API, add more data to the default endpoints, or even create your own endpoints. All of this without needing an extra plugin.
In practice, on a site like mine you now have many new ways to interact (view, create, edit) with the data on my site. Here is a list of the routes that are currently available on my site:
What can you do?
Want some examples? Here are a few things you could do with the REST API:
[jeherve_post_embed wpapi="true" url="jeremy.hu" tag="rest-api" include_images="true" include_content="false" include_excerpt="false" include_credits="false" image_size="200,150" number="10" headline="All my posts about the REST API on this blog"]
Error in the response. We cannot load blog data at this time.
You can build a React or a Vue.js app to display posts from a site:
You can add data to the default endpoints, and use that data in your apps. For example, my Color Posts plugin adds information about the post’s average color to each post:
Jetpack, for example, adds information about Related Posts:
But that’s only the beginning! Many websites and services already use the WP REST API for different projects:
- Wired.com uses it for widgets, liveblogs, and more.
- One of the top mobile cooking apps in Turkey uses it to manage all recipes.
You get it: the sky is the limit (almost)!
Want to play with the REST API yourself? The documentation is available here.