WordPress APIs: What are they and how to use them

WordPress APIs: What Are They and How to Use Them

The WordPress JSON REST API has created quite a buzz in the WordPress community, offering new possibilities for developers and content creators alike.

While it may sound complex, understanding key terms like JSON, REST, and API can simplify how you interact with WordPress’ wide-ranging capabilities.

What is an API?

API stands for “application programming interface,” which is essentially a set of programming instructions and standards that allow different software applications to communicate with each other.

Imagine one software application giving directions to another—an API is the set of agreed-upon rules that govern this interaction. When one piece of software sends instructions to another, the API facilitates the action or provides the necessary information.

You can think of an API as the “user interface” between two software systems, handling the communication of data and task execution, but invisible to the end user.

a laptop on a wooden desk

Examples of APIs

Having access to an API is awesome when you’re developing web applications. When an API is released to the public, it means the developers created solutions that are powered by the software’s service. Oftentimes, they take away the need to reinvent the wheel for many tasks, since they have already been created.

A great example of an API is Amazon. Amazon released its API so that developers can easily access products and their information. Having access to this makes it easy to post links to products on Amazon, with updated prices and the option to buy.

Another example of APIs interacting would be concert ticket purchases. To officially purchase tickets, you need to enter your credit card information. An API is used to send your credit card information to a remote application, which then verifies that the credit card information is correct.

Once everything checks out, the remote application sends a response back to the ticket website saying it’s okay to proceed, at which point you’ve successfully purchased the tickets. When all this is going on, you only see one interface, which is the ticket website. It’s a seamless process; behind the scenes, many applications are working together using APIs, but you as the user don’t notice when tasks are handed from one application to another.

APIs and WordPress

Amazon and ticket purchases are great examples of how APIs work together, but how does this apply to WordPress?

Well, all the same ideas apply. With the WordPress API, you are able to push and pull data into and out of WordPress.

The API is a key tool that developers can use to easily share data from their WordPress website to other websites or applications. Specifically, this API lets you perform create, read, update, and delete (CRUD) actions on WordPress content. A few examples of the content types are:

  • Posts
  • Custom post types
  • Pages
  • Taxonomies
  • Users
  • Media

What does REST mean?

There’s no napping or snoring here—REST refers to the architectural style of an API. REST stands for Representational State Transfer.

Remember how we mentioned that an API gives the specifics for communication so programs can communicate with each other? REST API’s are designed in such a way that they provide a lightweight method of communication, which saves bandwidth. The WordPress JSON REST API does just this, making it a great option when there is a high volume of data.

We’ve just scratched the surface of REST; if you’d like to learn more, check out this REST helpful tutorial.

JSON format

To access data, we need a source to pull from. This is where JSON comes in. JSON stands for JavaScript Object Notation.

JSON is easy for both humans and machines to read and understand. It’s the perfect way to store information in an organized, easy-to-access manner. Because JSON is so simple to access, this makes it a great fit for creating REST APIs and is the perfect solution for the WordPress JSON REST API.

Here’s a basic idea of what JSON format looks like:

[javascript]
{“employees”:[
{“firstName”:”Jane”, “lastName”:”Smith”},
{“firstName”:”Anna”, “lastName”:”Olsen”},
{“firstName”:”Josh”, “lastName”:”Jones”}
]}

[/javascript]

JSON format in WordPress

JSON doesn’t just write itself, but don’t worry, you don’t have to manually create the JSON file. There are plugins that can create it for you. With one of these tools, the site’s data will be in the correct format, including users, posts, pages, taxonomies, and more.

Using the JSON REST API

Using the API is pretty self-explanatory; you’ll be grabbing your site’s data in simple JSON format. And if you have a plugin installed, you can play around with seeing your site’s posts in data form.

Retrieving or updating data is as simple as sending an HTTP request. HTTP is a request/response protocol. First, you send a request for data and then the data is is sent back as a response.

GET method

The GET method is used to retrieve information and has no effect on the data. Simply send a GET request to /wp-json/wp/v2/posts. Want to search for something? For example, if you’re searching “development” you’ll get the results with the GET request /wp-json/wp/v2/posts?search=development.

POST request

A POST request is used to send data. With the capabilities of the new API, for example, you could update a user. Let’s say you want to update the user with the ID of 10. All you have to do is send a POST request to /wp-json/wp/v2/users/10.

To try this out, we’d recommend using Postman, a Google Chrome extension.

More Javascript in the mix

Backbone.js and APIs

Backbone.js is a great way to work with the API because it is a framework designed for working with REST APIs. The WordPress API includes an easy-to-use Javascript API based on Backbone models. This allows plugin and theme developers to get up and running without super in-depth effort and knowledge about the details of getting connected.

There’s a lot more to it, but Backbone gives structure to web applications by providing models, collections, and views, and connects it all to the WordPress API over a REST JSON interface.

backbone.js wordmark logo

What does this mean for WordPress developers?

With the availability of the WordPress API, new ways of utilizing it have increased and will continue to do so as it gains popularity. The WordPress API can improve just about any existing WordPress functionality that relies on Javascript. Here are a few examples:

  • form validation/submission
  • Backbone.js themes or plugins
  • infinite scrolling

It’s also a great way to show content from other sources. Now, it is easy to display content from an individual site within a multisite setup. It’s also possible to display content from an entirely separate WordPress site. In addition to showing content, the content can also be updated more easily and effectively.


Now that we’ve gone over some of the basic terminology, we know that JSON is the notation, REST is the architectural style, and API is the interface they make up. Knowing the basics of the API and its capabilities will ensure you are off to a good start when you explore the new possibilities with the WordPress API.

Get started

Build faster, protect your brand, and grow your business with a WordPress platform built to power remarkable online experiences.