A quick guide on how to get going with the WordPress REST api so that you both understand it and can use it.
When I was learning how to play the Cello one of the most important things was to get yourself setup correctly in the first place. Find the right kind of chair, adjust the spike, tune up the strings, tighten the bow and apply rosin. This was good practice for many things in life, (remove as) unless you get setup properly in the first place you will certainly be making your life harder than it needs to be. The REST api is no different.
The first thing you need is a copy of the api to work with on a fully functioning WordPress website, and I will presume that you have the ability to create a site where you can add code and manage plugins. The site I will be using for this is called blogimport.dev, running on my local machine, so if you want to just cut and paste the example code then this is the domain to setup.
At the time of writing, the api comes in two flavors, version 1 and 2. On the basis that version 2 is the one that is to be bundled with WordPress in the not too distant future I will concentrate on that version and it can be installed via the Add Plugins option in the dashboard.
Secondly for the benefit of learning and testing I have been using the basic authentication plugin which can be downloaded from the teams github account. You will need to install this manually as I don’t believe it is available on the plugin directory.
With these two plugins enabled you are good to go and you could start exploring your site with get requests from your browser right now. This is however not the most satisfactory experience and you will do far better by installing something else to help you. My choice is Google Chrome Postman, which I will be using, so if you want to follow the rest of this entry I will show you how to use it with your setup.