Part 1: WordPress REST API – what it can do and how can it be of use to you

The revolutionary REST API add-on is nothing new to anyone in the WordPress world. Rumors about it started even before it had been created and people are still talking about it three years later. The official REST API manual will tell you that "only your own imagination is the limit of what you can create with WordPress REST API." What is so revolutionary about the REST API and how can you use it?

MICHAELA GRYGAŘÍKOVÁ
  • MICHAELA GRYGAŘÍKOVÁ

  • 05. 03. 2019
  • 6 min read
Zkopirovat do schránky

What is WP REST API?

Originally, the REST API had a form of an external plugin to the WordPress version 4.4 Clifford. Its addition to WordPress core is being hailed as the revolutionary step that will significantly shape the future of the platform. The API opens new ways of how to work with WordPress. In short, the REST API is a universal connector between WordPress and other software applications. It enables WordPress to communicate with other web properties no matter what programming language they’re written in.

What do the abbreviations API, JSON, REST mean?

API (Application Programming Interface) is an interface connecting two different application. Its use is very widespread on the Internet. For example, if you share a post on Twitter through a third-party application, you use the Twitter API.

REST (Representational State Transfer) is an application interface architecture designed for a distributed environment. A RESTful architecture uses HTTP requests to publish, read, update, and delete data between two independent sources.

API brought about new opportunities

As we already mentioned, API allows you to link WordPress to other applications, no matter what languages they are written in. Its main benefits include the ability to work with content and also administer WordPress websites.

  • Integrating third-party content. Because API allows you to communicate with other technologies, it’s possible to get content from almost anywhere. The WordPress platform allows programmers to use it as an authoring system for their own content stored outside of WordPress, or vice versa, the contents of the WordPress Web site can be used in another application using the API (see a specific example below).
  • A new form of administration. The API also brought new capabilities in administration. It allows you to manage WordPress in addition to the standard administration backend and other tools that are typically written in JavaScript but can also be in the form of a mobile application. You can use, for example, WordPress for iOS and Android from Automattic.
  • Simpler and closer to app developers. With the API, WordPress has also approached developers and programmers who have no WordPress experience. If they want to add specialized information to WordPress regularly, they can create a plugin or write their own application in a preferred programming language.

Do you know that...?

Master Internet has been providing server hosting services for 20 years. By renting a dedicated server you can free yourself from any care of hardware and profit from full performance of a server in ideal conditions of a professional datacentre.

More about dedicated servers

What does API do in practice?

We already know what the API can do in theory, but how best to use it in practice? Whether you have the idea of a new project or working on existing ones, the API offers you room for improvement and innovation. Let’s look at some examples.

  • Unify content from multiple pages. Imagine leading a company with many affiliates, such as a bank or fast food franchise, and each of these branches has its own WordPress site. Your central website can then use the API to unify new posts from each page to the main one to give users news from all locations. This was used by Washington State University, which unified the content from the 1083 pages through the WordPress REST API.
  • Synchronize content across multiple WordPress installations. With proper authentication, you can control the contents of your own backend with the API. This can be used, for example, by news sites to create a shadowed WordPress installation (available only on their intranet) where they collect and organize ideas, and will be separate from the main WordPress installation. Using APIs, they can link this shadow page to the main page and publish articles when they are done. This will keep the main page clear and safer, as the workspace is separate from the user page.

How did we use the API in Master?

We have also taken advantage of the API’s capabilities in Master Internet. Our software division is developing a variety of mobile apps and we have our own website for each one of them. We wanted the sites of these apps to promote each other, and this put us in front of the problem: how do we easily distribute data between different sites without disrupting the user-friendliness of their administration?

That’s where API helped. Based on WordPress, we’ve devised a multi-party system, consisting of a central website that collects data about the app, individual app sites, and a support library. Sites communicate with the Central Website and any change in the information will be reflected on each of the other sites.

Do you want to start with the API in WordPress and use it in your project? Wait for the next part of the series! We will bring you a guide for beginners with many practical examples.

Líbil se vám článek? Ano / Ne