WordPress REST API
WordPress is the most popular CMS used on the internet and has been for some time. Because of popularity and being open source software there are 100s/1000s of people looking to improve the functionality of WordPress. One of the most exciting new features of WordPress is the HTTP REST API development.
Calypso can be used on all of your WordPress.com websites or any websites using the Jetpack plugin. It can be used to replace the admin area of your site and communicate with WordPress directly from this desktop application.
Another benefit is that everything can be changed in real-time, so if you have a multi-author blog you can see the changes from the other authors in real-time.
The main frameworks that calypso takes advantage of is node.js and React.js libraries and a number of custom built functionality on to.
To see this in action, view the following video.
WordPress REST API
The functionality for the REST API is intended to be merged into the WordPress core code but for the time-being it's development is happen has a feature plugin you can install on any WordPress website.
When this is installed on your site you'll be able to to get all the posts in your site by using the URL
/wp-json/wp/v2/posts or if you want to search for posts with a certain keyword then you can make a GET request to
The way your RESP API will be able to be accessed by external websites is by authenticating the HTTP request by using either cookie authentication or OAuth authentication.
The REST API recommends that authentication should come down to the type of request you're making.
- Are you a plugin/theme running on the site? Use cookie authentication
- Are you a desktop/web/mobile client accessing the site externally? Use OAuth authentication, application passwords, or basic authentication.
Cookie authentication is already built into WordPress it's used when you log into your WordPress dashboard it will store a cookie on your machine to authenticate your requests, the REST API does this by WordPress Nonces.
OAuth Authentication is the main method when working with external websites. This process gives clients access to the API via tokens. Tokens can have an expiry to even turned off to stop clients accessing the API anymore. To use OAuth with the WordPress REST API you will also need to install the plugin OAuth.
When this is installed you'll need to create a new client which can be created from the admin area. The client will need be assigned a token allowing it access to the REST API by sending the authentication in the HTTP headers of the request.
What Data Can We Access?
As you need a plugin to access the REST API in WordPress one of the main worries is how much coverage do you get to the data in your WordPress CMS. Let's have a look at what data you can access from the REST API.
To see the data you can access you can view the API document using the link below:
Using the API you can access all the posts stored in your WordPress CMS.
Get List Posts
To get a list of posts where you will commonly see on the homepage of a WordPress theme, where it displays the latest 10 posts of your blog you can use the following GET request.
The following arguments can be passed to the GET with through querystring to change the criteria of the posts returned.
An example of using these arguments for say getting all posts by a certain author can be done by using the
author argument with the ID of the author.
If you want to create a search query then you can use the
search passing in the search term that you want to use.
Get A Single Post
You're able to get a single post by the post ID by querying the API by using the following GET request.
This will return the post information for this post ID. But in most websites you'll want to use a nicer looking permalink with the post slug, then you'll be able to get the full post information by using the GET request.
Create A Post
Update A Post
Delete A Post
When a post is being edited WordPress admin area will auto-save so the post, this adds a revision record into the database, the same happens when you update a post. This revision record can be used to display the history of the content. The following endpoints can be used to interact with the post revision records.
List Of Revisions For A Post
Retrieve a Post Revision
Delete a Post Revision
Pages is just another post type in the cMS, the endpoints therefore will be similar to the posts endpoints but change the posts with pages.
List All Pages
Retrieve a Page
Create a Page
Update a Page
The media endpoints are used to handle the request for any sort of media files attached to a post such as featured images. A media endpoint can be used to customise the data attached to a certain image, such as the stored title, alt tag etc.
Retrieve a Media
Create a Media
Update a Media
Delete a Media
If you have multiple post types in your application then you can use the following endpoints to interact with post type data.
Retrieve a Type
Post statuses are used in the author workflow to show what stage the post is in, you can use these endpoints to get the registered post statuses in your applications.
Retrieve a Status
Using the following end points you can interact with comments published on the blog. This allows you to get all comments for a certain post and even create comments on your theme.
Retrieve a Comment
Create a Comment
Update a Comment
Delete a Comment
Most websites will use taxonomies to organise the content structure of the site, using the following endpoints allow you to get a list of the taxonomies used on your website.
Retrieve a Taxonomy
Use the following endpoints to interact with the category taxonomy on your WordPress website.
Retrieve a Category
Create a Category
Update a Category
Delete a Category
Use the following endpoints to interact with the tags taxonomy on your WordPress website.
Retrieve a Tag
Create a Tag
Update a Tag
Delete a Tag
If you need to interact with Users on your WordPress website then there are the following endpoints to get users or create new users.
Retrieve a User
Create a User
Update a User
Delete a User
In the next couple of weeks we're going to investigate how you can create a WordPress theme using VueJS to access the REST API to replace the PHP version of themes. I'm also going to see if I can replace the existing theme on Paulund and use a VueJS theme moving forward.
Fastest WordPress Hosting With WPEngine
Stunning speed, powerful security, and best-in-class customer service. At WP Engine.
Join the weekly newsletter
Sign up for our newsletter. You'll be updated on new tutorials as they come available.
Subscribe today and get a 50% discount code to Paulund