This is day 20 of my WordPress Developer Advent Calendar.
I love how all new major additions to WordPress core are being developed as plugins first, so that they can be tested and put through their paces. One of these plugins is WP-API, which gives your WordPress site a REST API. If you are unsure what REST is, then I suggest you read up on the topic first:
- A Beginner’s Guide to HTTP and REST
- What exactly is RESTful programming?
Make WordPress RESTful
To give this new feature a spin, this is what you need to do:
- Download the WP-API plugin and activate it on a local WP install.
- Make sure your permalinks are set to “post name”.
- Install the best API testing tool available : PostMan (this is a chrome extension).
Make Your First RESTful Request
Now that it is installed and running, open up Postman and do a GET request to:
Where http://local-wp-install is the location of your local WordPress environment. In my case it was http://wp/wp-json.php and you can see the result I got in PostMan:
The result you get back is a JSON document which includes all the RESTful URL’s or “routes” that you can now access in your very own API. Very cool. Now let’s get back all your posts. I did a GET request to
http://wp/wp-json.php/posts, and the response was:
To get back a listing of all post types in your WordPress install, do a GET request to
Now this is only the tip of the iceberg, and you can do a whole lot more with the API. For more detailed documentation, check out:
- The Getting Started guide.
- Working with Posts - how to retrieve, save, update and delete posts via the API.
- Extending the API - really interesting for plugin authors.