WP Rest API – The Mobile Shift

It's no secret that mobile web use is a growing trend.  Over 1/3 (38.6%) of all web traffic comes from mobile devices, and that number isn’t slowing down. In May 2015, Google confirmed that there was more google searches taking place on mobile devices than on desktops in 10 countries (including the US). Experts predict that in the coming years, mobile web traffic will overcome desktop usage.

As mobile web use becomes increasingly common, it places an additional demand on developers and WordPress users to design responsive sites. Thus, developers and non-coders alike were elated when WordPress 4.4 released an integrated option for responsive images (with automatic retina support) in December 2015.

However, the real mobile shift can be observed with WP REST API, which lets anyone build mobile apps using WordPress. One day, WordPress will be able to secure mobile apps together like a platform. So let’s dig a little deeper into WP REST API, and see what this exciting new tool is all about!

API and WP REST API – What are they?

API or Application Programming Interface is an interface that acts as a software intermediary, and governs how one application can talk to another and share data in limited, clearly defined ways. It can be thought of as a contract provided by one piece of computer software to another.

Some examples of APIs in action

  • A website can post direct links to Amazon products (using their public API) with updated prices and an option to "buy now"

  • Using a 3rd party program to post to Twitter (uses Twitter’s API to connect it to your program)

  • An App uses Google Maps to display its location information

  • An app, game or website integrates Facebook features (login, messaging etc.)

So what is the WP Rest API?

Technically speaking, WP REST API is a lightweight data-interchange format, and based on a subset of JavaScript code language. What that means is that it’s a very powerful tool that humans can read, write and edit easily, and that machines can analyze and create. The WP API allows you to take CRUD (Create, Read, Update and Delete) actions to many different kinds of WordPress content: posts, pages, custom post types, media, comments, taxonomies, users etc.

The idea for WP REST API was proposed just after theWordPress Community Summit in 2012. At that time, there were APIs all around the Internet, and the WordPress community was eager to bring their functionality to WordPress. On October 8th, 2015, part of the infrastructure of REST API was first merged into the Core. All the code that allowed you to create your own endpoints is now there. However, prebuilt endpoints aren’t in the core. While you can create your endpoints without a plugin, if you want to include all endpoints, you would need the plugin.

For those who are curious to learn more about the introduction and development of WP REST API, be sure to check out Ryan McCue’s (co-lead of the REST API project) video:

WP REST API: Why do we care so much about it?

WP Rest API is the new universal connector, and is considered revolutionary because it enables WordPress to communicate with any other web program or property, regardless of the programming language they are written in! In other words, it is transforming from it’s humble origins as a blogging solution (we know WordPress so much more than blogging today!) into a full-featured application platform.

This presents a world of possibilities, and marks the opening of WordPress to the rest of the Internet, as it becomes a full-scale application platform. Rachel McCollin, a WordPress author and web designer specializing in responsive WordPress development notes that

Just about any application could interact with WordPress in the future

How developers and designers can leverage WP REST API to work their magic

There really are no limits within the WP Rest API. If you can think of a desired connection, a WordPress developers can make that happen! Here are some examples of the best ways that WP REST API has been used so far

  1. The New York Times have been long-time users of WordPress, so it’s not surprising to see the are early adopters of WP REST API’s capabilities. They have been using WP REST API to power their live coverage blogs. Their live coverage plugin uses REST API, and also Backbone.js and React.js which they use to communicate between the WP backend and a custom editor made with Backbone.js. Then, the content is filtered and finally it is shown on the front end by a React-based app. This is a perfect example that shows how WP REST API functions regardless of the differences in programming languages. You can watch the full talk about the project by NYT developer Scott Taylor.
  2. StoryCorps is a national project to instruct and inspire people to record each others' stories in sound. Last year, they used the WP REST API to create iOS and Android apps to encourage users to easily share their stories from cellphones. The way it works is that the content is synced from the WordPress backend from the app. The content that is published on the website will also get synced to the mobile apps. For example, if you upload a story from the app, you can see if on your account on the website, and then if something is published on the website that is also relevant to the app, it would be updated on the application. This project demonstrates the scalability of WordPress and the REST API.
  3. HumanMade, a WordPress agency that also contributed to the REST API itself, created NomadBase. This app shows you were Digital Nomads are currently located around the world. This app was inspired when Digital Nomads meetup at a DNX conference, and they wanted to inspire more Digital Nomad meetings and collaborations.
  4. Custom Contact Forms is a plugin that’s used for building forms and adding them to your WordPress website. The Plugin was built using WP REST API, and uses API on both the front and backend. As of February 2016, Custom Contact Forms is currently the most widely used plugin running the WP REST API with more than 70,000 installations.
  5. The Public Knowledge Project, aims to supply academic journals with free software for managing their online versions, used the REST API to manage plugin submissions. By offering free software, the PBK’s goal is to make academic knowledge increasingly available to the public at large.

What our WordPress experts say

Nick Baldwin explains why he thinks WP REST API is a big deal:

The WP REST API allows you to use WordPress as a backend service for an app. It sounds simple, but the implications are huge. It creates an exciting number of interesting opportunities.

For example, if you have a client with a large amount of content, like a news organisation, often they find it useful to have a native (or cross-platform native, using Apache Cordova or similar) app with all of their content. The WordPress REST API creates a simple way for the app to retrieve all of that content, without creating the need for the client to update their content in multiple places. Instead, their WordPress site serves as both a site, AND a backend for their app.

For another example, let's say you have a client who owns an entertainment venue; normally you would make them a nice WordPress site which publishes their event schedule (as simple posts or as a custom content type). With WP REST API, you can also make an app for this client. The app could pull the information and images for all the upcoming events, and provide functionality for online booking (which could be handled by a third-party platform, or by WordPress itself). So your client would have an easy way to post information about upcoming shows, and have all of that information published to both WordPress AND their native app. You can even set the app up to give push notifications about newly listed concerts and shows.

These are just a few simple examples, but the applications are endless.

The real advantage is the ease of management. Because this approach allows the client to manage the content for their native app and their WordPress site from just one place, without the need for creating an expensive custom API.

Need help with your WordPress website? Hire Nick Baldwin or any other of our top-notch WordPress experts.

WP REST API: Future Implications

JavaScript - the new PHP?

The WP REST API is making JavaScript increasingly important. Not only does JavaScript often come into play with the WP REST API, but the WordPress.com admin is written completely in JavaScript instead of PHP/HTML and it is 100% REST-API based. Matt Mullenweg repeatedly stressed in his State of the Word 2015 address that JavaScript and API-driven interfaces would be extremely important to the future of WordPress and the web in general.

He also urged that audience members should “learn JavaScript deeply.” Some are even going as far as to bill JavaScript as the “new PHP.”

More flexible, simple WP development

Billed as the “universal connector” WP REST API makes it possible to connect WordPress with other things outside of the WordPress world. In programming terms, this means that WordPress can connect for the first time with additional tools and programming languages that go far beyond HTML/PHP in a new efficient and standardized way (while this was possible in the past, it was limited). Advances in other frameworks, such as Ruby on Rails, will ensure that these then become available for WordPress, making plugins and themes more dynamic, flexible and extendable.

Easy 3rd party integration and the App Market

As we’ve seenWP REST API allows WordPress to function and connect with other programming languages and technologies. With this, it will be possible to pull content from almost anywhere. Conversely, it will be equally simple to push WP content into other applications. The JSON format in WP REST API is natively supported by both iOS and Android, opening the door wide for WordPress mobile apps.

Increased demand for WordPress developers

Since WP REST API provides exponentially more opportunities and applications for WordPress, there are naturally more work opportunities for experienced WordPress developers and designers. The API will open up the platform to more developers from other disciplines, but it is likely the demand for WordPress specific professionals will rise.

Conclusion

WordPress REST API marks an exciting new moment in WordPress development history, where WordPress is now open to technology outside of the WordPress universe (and vice versa). It not only means new, creative ways to manage content (both WordPress and third-party) but increased flexibility and extensibility for developers. While developers are being encouraged to learn JavaScript as it plays an increasingly important role with WP REST API, there will most likely be an increased demand for WordPress professionals to use their expertise to leverage this exciting feature to its fullest potential.

Now your turn! Tell us what different ways you’d like to see the WP REST API implemented, or cool ways that you are already using it. What are you excited (or dubious) about? Do you believe this represents the future of WordPress?Quality: The Codeable Differene

  • Frank McClung

    Great article. Will WP REST API make mobile app development as easy as website development with WordPress?

  • Ok

    Took long enough. Looking back, I’m shocked this wasn’t in place 5 years ago.

  • Audacitus

    @frankmcclung:disqus Looking at it now? Yes. I’ve integrated WP-API with a mobile app using the IonicFramework2 in less than a month: http://market.ionic.io/starters/magaza