rest API

Using the power of WordPress REST API for your business

What is a REST API?

Our relationship with computers is mostly a one-way street. We use computers as tools for work or play, and we expect them to provide information on-demand. But in the background, computers are talking to each other to send us what we need via networks and software API’s.
API stands for “application program interface” and is a shorthand way to describe the software used to translate between computer systems and networks that may not speak the same programming language. While API’s could be any number of interfaces between computers that don’t involve people, when we at Nashville Geek say API, we are referring to using a website to talk to another service, website or person.

Using the web to operate an API is known as REST—short for “representational state transfer” or REST API. REST APIs commonly use commands located in the URL to interact with the software behind the browser. This allows you to get what you need from the service without having to use a complicated visual interface or specialized programming language.

geek ideas iconUsing the web to operate an API is known as REST—short for “representational state transfer” or REST API.

REST APIs commonly use commands located in the URL to interact with the software behind the browser. This allows you to get what you need from the service without having to use a complicated visual interface or specialized programming language.

You might not even realize you are using a REST API when you are on the web. YouTube is a great example. When you want to watch a particularly notorious video, you might use this URL:  https://www.youtube.com/watch?v=dQw4w9WgXcQ)

This URL is an API endpoint that activates YouTube’s “watch” command using a video with the ID of dQw4w9WgXcQ. As opposed to a URL for a single webpage, you’ve just talked to YouTube’s network and told it you wanted to watch a video. Pretty cool, eh?

Another example from YouTube uses the “user” command of the software to give us information about a particular YouTube user. In this example, https://www.youtube.com/user/RickAstleyVEVO, you are telling YouTube to give you the information on user “RickAstleyVEVO”. Going to this URL will take us to Rick Astley’s user page where you can carry on a fine tradition of rick-rolling your friends.

The Nashville Geek website also includes a REST API. By going to the URL: https://nashvillegeek.com/wp-json/wp/v2/posts, you can see how our website might look to another service that would use this data to republish our posts. Below, we’ll explore how a REST API would be practical for your WordPress site.

The WordPress REST API

Starting with version 4.7, WordPress includes an optional REST API as part of the core program, allowing you to use your site as a conduit to other sites and services. Most of the things you do with your website can now be either remotely triggered or transmitted anywhere you choose. You might think of posts and pages as static things, but now they can be used like a service! This includes posts, pages, users, custom data and media—anything published through your site. Now, just like the example with Rick Astley, you can create endpoints for your WordPress site that allow users to quickly access specific data without having a URL link to a single page.

Not only does the WordPress API allow users to access data without a webpage, but with your permission, it allows services to use those endpoints to create or modify entries. In other words, you can manage data on your website without having to use the admin interface. You could even have the front-end of your website in a completely different system, like a mobile app or the physical web, and still use WordPress as the management and permissions center.  That’s huge. Suddenly WordPress is no longer about being a single website, but about being the control room for your web-based software.

How Can the WordPress API Help Your Business?

One of our clients, ChanceLight, challenged us to streamline their administrative overhead across nine websites and hundreds of locations. If anything changed with a single location, such as staff contacts, emails or phone numbers, they would have to log into each website separately and make that edit. We proposed creating a service that would allow them to make a change in one place and immediately update on all their web properties at once—a perfect use-case for WordPress REST API.

Now, when ChanceLight updates a location in the WordPress-based management center, the API detects the change and transmits those updates to all the sites on the network at once. This is using WordPress as a service instead of as a website—it’s not publicly accessible and has no front end. That’s so cool!

WordPress isn’t limited to either one or the other—your site can act as a hybrid of service and a site. As an example, you could give special access to hidden content when users joined your email list. Your email service would listen for new members to join the list, then automatically send a request to the REST API to create a user for them on your WordPress site. By syncing with the email service, you could likewise cancel your new user’s access if they opt out of your email list.

Now that we can use WordPress as a service, the possibilities are endless!