WordPress API Basics: What it Means and How to Use It

You may have heard the buzz about the WordPress JSON REST API. This is big news for WordPress users and cause for celebration!

JSON, REST, API—this is a lot of jargon for one name, however, so let’s break it all down.

What is an API?

API stands for “application programming interface,” which is a set of programming instructions and standards for accessing a web-based software application or web tool. Imagine “software one” that is giving “software two” instructions.

An API is an agreement between the two, and the lines of communication are open. Basically, what they say to each other is something along the lines of “when you give me an instruction, I will perform the action, or return the correct information.”

As we search the web and use various software solutions, we are used to user interfaces with specific layouts, buttons, and graphics that we interact with to complete our desired tasks. All this is useless to a machine because all they care about is data and what they need to do and how they interact with it.

An API is the software’s version of the “user interface,” giving instructions to a second software on how to get data and complete specific tasks. They are completely invisible to users who are using the web application, and are simply a software-to-software communication.

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 have easy access to the 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.

API 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.