Home / Blog / The Complete Guide to WordPress REST API Basics
WordPress Rest API

The Complete Guide to WordPress REST API Basics

What is the WordPress REST API?

The WordPress REST API is an interface that developers can use to access WordPress from outside the WordPress installation itself. You access it using JavaScript, which suggests it is often wont to create interactive websites and apps.

REST stands for Representative State Transfer and API stands for Application Programming Interface.

What is an Application Programming Interface (API)?

An Application Programming Interface, or API, is defined as:

“An interface or communication protocol between the client and the server that aims to facilitate the construction of client-side software.”

If you aren’t conversant in APIs, which will not help considerably . to place it more simply, an API may be a set of code that permits one system to interact (or “interface”) with another. If you’ve ever added a Google map to your WordPress site, you’ve used Google’s Maps API, which allows your WordPress site to interface with Google Maps.

These systems don’t get to be completely separate. WordPress already has multiple APIs, for things like plugins, settings, and shortcodes.

The difference with the remainder API is that it allows systems outside your WordPress installation itself to interact with WordPress, which is where the remaining part comes in.

What is Representational State Transfer (REST)?

Representational State Transfer, or REST, provides standards that web systems can use to interface with one another. Without REST, two systems wouldn’t be ready to understand one another then send data back and forth.

For an application to be RESTful, it must conform to 5 principles:

  • Uniform interface. The URLs wont to access resources within the system need to be uniform, consistent, and accessible via a standard approach like getting (more of which shortly).
  • Client-server. Client applications and server applications must be separate, in order that they are often developed independently of every other. If the server-side technology (i.e. WordPress) changes, the server-side application (an app, for example) must still be ready to access it via an equivalent simple method.
  • Stateless. The server doesn’t turn when a replacement request is formed using the API. It doesn’t store the requests that are made.
  • Cacheable. All resources must be cacheable, to enhance speed and conformance to web standards. Caching is often implemented on the server or client-side.
  • Layered system. A RESTful system allows you to use multiple layers to access it, storing data in intermediate servers if it must. The server can’t tell if the ultimate client is directly connected thereto.

All of those constraints relate to sites and applications and govern the way an application can interface with the API.

How to Access the WordPress REST API?

How does one access the WordPress REST API?

To access the WP-REST API, you’ll get to access your site via the instruction. With WordPress, this is often called WP-CLI. You don’t do any of this via your admin screens or by directly accessing the code on your site.

Let’s take a glance at how you start.

Accessing WP-REST via WP-CLI:

WP-CLI is that the WordPress instruction Interface. It allows you to access and work with WordPress via the instruction Interface (CLI) on your computer. WP-CLI is pre-installed with all Kinsta hosting plans.

To access the CLI, open Terminal on a Mac or in Linux, or prompt in Windows.

To access a foreign site, you would like to SSH to your server to access it via WP-CLI (Can’t connect via SSH? find out how to repair the SSH “Connection Refused” Error).

To access an area site, you merely got to use the right directory structure from the instruction. It’s an honest idea to experiment with the remainder API on an area test site before trying it on a live site.

You’ll get to specifically access the remainder API for your site, like this:


You can then add elements after this to access certain sorts of data, which we’ll check out in additional detail shortly. These elements are called endpoints.

Overview of WordPress REST API Commands:

Once you’ve accessed your site and you recognize the way to use authentication (and indeed whether you would like to), you’ll get to use one among a variety of commands to interact together with your site.

The commands you’ll get to use are:

  • GET retrieves a resource like a post or other data.
  • POST adds a resource to the server, like a post, attachment, or another resource.
  • PUT is often wont to edit or update a resource that’s already on the server.
  • DELETE removes a resource from the server. Use it with care!

About wpscriptor

WP Scriptor is WordPress Trainer and Developer in the Karachi, Pakistan area. We’re WordPress developer’s goal is to make the world of WordPress accessible to everybody. We publish weekly in-depth WordPress tutorials and WordPress techniques on the site and to our mailing list, and we link out to cool WordPress stuff elsewhere on the web most weekdays.

Check Also

Add RTL Support To A WordPress Theme

How to Add RTL Support to a WordPress Theme