The WordPress REST API is here… but what is it?
19th August 2016 by Chris Townsend
It’s time to get faster with the WordPress API
At The Partnership, we’ve used WordPress a lot. It must come as no surprise that when a new feature is released, our Digital guys get excited and want to get working with it straightaway. But before we get carried away, we’ll first introduce the world’s most popular Content Management System (CMS).
WordPress was created in 2003, and its original purpose was to enhance typography of everyday writing. Since then, it has evolved from a simple blogging tool to becoming the most used CMS on the planet. 25% of all websites on the internet are utilising it, that’s about 244 million websites. Wow. It’s a free to use open source platform which can be used for a small personal blog to a large corporate website, and with its huge community support and endless number of uses, you can see why WordPress is the leading CMS platform. Now that you’re familiar with WordPress, let’s explain what happens when we load up a WordPress site.
What we currently have without the ‘WordPress REST API’
To get the content of a WordPress website, a request is made to the CMS. This information is then packaged up and sent back to the web page and a user is able to view it. Doesn’t sound too bad does it? But what if we want more information on that page? Well we have to make another request and reload the page with that extra information, adding unnecessary seconds to the page load. In an age where customers want things faster, quicker, instantaneously, we can’t afford to waste these seconds.
During the journey of a website, you as a user could do this multiple times and each time you are returned to a near identical page, just with different information. So why all that loading? Let’s put it another way. We have a letter which details what we would like to buy from a specialist supplier, but to get this letter to our destination we have to deliver it ourselves. We must find a mode of transport, get fuel, find out the route and then process the journey to deliver our letter. The supplier will then take our order, process that in their factory and return us our goods. We then need to source transport for our new goods and deliver them home. This is what happens each time you make a request for more information on a WordPress website. But now there is a much more efficient way – the REST API way.
The delivery guy is here
REST stands for Representational State Transfer but to start let’s ignore REST (as this is more useful to standards when programming), and focus on API. API Stands for Application Programming Interface. It is essentially a messenger between entities, a digital ‘middleman’.
The REST API introduces a way of getting the contents of a page without having to reload it. So, rather than a user having to reload the page each time to get more information, they can get it instantly at a simple click or touch. The REST API is our delivery guy for WordPress page data.
How will we use it?
A feature like this clearly has lots of benefits to our clients, as seamless usability is something that every company wants for their website. This is where we think that the REST API will come in handy. Taking WordPress websites, and giving their users the kind of experience they would expect from an application.
The app craze has died down a lot over the past 12 months but one of the huge benefits a native app offers is a quick and effective interface. There are no page loads needed in a native app, which is why it is able to offer a better experience than a web app.
The REST API can limit page loads and make it easier to deliver this native app experience to your customers, and that’s what we intend to do.
Other potential benefits
Now, it’s not too wild to think that some of your potential customers might browse your website on their work commute. One of them might try to access your website from their phone. They’re browsing deeper and deeper, digging out new information with each page they visit. But they start going through a tunnel. Their service is cut off, and immediately the whole experience is far less enjoyable for them. In most circumstances that potential customer may put their phone down and forget to even look at your service again.
With the REST API a clever developer (like our TP digital team) could have delivered all the content to your customer’s device and cached it into its memory. This would ensure that even when their phone lost service, they could still use your website and would be able to access that critical information. But how?
Well, the REST API stores content on your device’s ‘local storage’. When you first visit a website, the site loads up and you’re good to go. Whilst you’re scrolling through and taking in that information, WordPress is working behind the scenes to fetch the content for the rest of the site’s pages. These are stored locally, so when you run out of service on your mobile for example, the browser doesn’t need to go back to the server. Instead when you click on a new page, it dives into your device and retrieves the contents of that page. Pretty neat, right?
As with all things connected to the internet, there are security concerns when being able to access data, which is why it is important to use trained and skilled developers in your projects.
When making a request to the WordPress REST API it is important to trust where the request is coming from. It is crucial to set the permitted origins of the request and transport the request in an encrypted form. Like in our supplier example it’s the equivalent of the letter being written in a secret code that only the supplier can read, and the origin is set by our wax seal on the envelope.
The REST API is an exciting new development to WordPress and we can’t wait to show off what we can do with it.