The WordPress REST API has been round for some time now, however working out what it’s and why it issues might not be instantly transparent to beginners and non-developers. Even so, this instrument is a at hand one to understand for customers of all stripes, because it lets you make the most of the acquainted WordPress interface only as a again finish, and expand the entrance finish the use of different equipment and languages.

This publish will supply an creation to what the WordPress REST API is and what it’s able to. We’ll additionally proportion a couple of steps that will help you get began the use of WordPress as a again finish for an app or site.

Let’s get to it!

An Advent to the WordPress REST API

There are lots of articles that provide an explanation for what the WordPress REST API is – we’ve even covered this previously – so we’ll stay this transient to keep away from repeating ourselves. Merely put, an Utility Programming Interface (API) is what allows connections between quite a lot of gadgets, packages, and information.

A helpful analogy is to think about an API as a waiter turning in requests and responses between diners and the kitchen. On this instance, you’re the diner, the appliance or database you’re seeking to keep in touch with is the kitchen, and your ‘meal’ is the information you’re soliciting for.

Representational State Switch (REST) is an ‘architectural style’ or form of API. It’s designed to be light-weight and calls for minimum bandwidth when used. The use of a REST API, you’ll be able to make 4 elementary forms of requests:

  • GET: Retrieves knowledge from the tool, utility, or database you’re speaking with.
  • POST: Provides knowledge to the tool, utility, or database you’re speaking with.
  • PUT: Updates already current knowledge at the tool, utility, or database you’re speaking with.
  • DELETE: Gets rid of knowledge from the tool, utility, or database you’re speaking with.

The WordPress REST API makes use of JavaScript Object Notation (JSON) to go back knowledge. So, while you put all of this in combination, you get a light-weight manner of speaking GET, POST, PUT, and DELETE requests between WordPress web sites and different platforms thru the usage of JSON.

Figuring out What the WordPress REST API Can Do

It should appear to be the WordPress REST API isn’t all that helpful to you, in particular should you’re now not a developer. Then again, there are lots of issues the API can do this even intermediate WordPress customers may need to take a look at, similar to:

  • Syncing content material. You’ll be able to use the REST API to allow other WordPress websites to keep in touch with every different. For instance, it is advisable to check out a site redesign through syncing content between your present website online and the redesigned model.
  • Syndicating content material. On a identical observe, you’ll be able to additionally mix content material from a number of other web sites. Take a industry with a couple of places every with their very own website online – you’ll be able to syndicate content from all 3 onto any other, complete website online.
  • Putting in a WordPress knowledge Google Sheet. The use of the REST API, you’ll be able to attach your WordPress website online and Google Sheets. This would let you organize your posts in a spreadsheet to stick on best of content material updates.
  • Growing cellular apps. By means of connecting your WordPress website online to a customized app entrance finish, you’ll be able to create a cellular app to counterpoint your desktop website online. That is at hand for scenarios similar to developing an app version of a WooCommerce store.
  • The use of ‘headless’ WordPress. If the entrance finish show choices for WordPress aren’t doing it for you, the REST API lets you use WordPress for all of your content material introduction and control whilst serving the content material to customers on a customized site or internet app entrance finish. That is referred to as ‘headless’ WordPress.

A handy guide a rough Google seek will flip up a large number of alternative ways by which the WordPress REST API is getting used. Then again, for the remainder of this publish, we’ll focal point on the use of WordPress as a again finish for an app or site.

Use WordPress as a Again Finish (In 3 Steps)

There are lots of techniques to make use of WordPress as a again finish. As such, this publish is extra of a common creation to doing so the use of the WordPress REST API, relatively than a whole information to construction an app or decoupled site.

Whilst the stairs underneath are simplified to lend a hand get you began, this implies you’ll most likely wish to analysis further steering explicit for your mission. Then again, realizing those fundamentals will assist in making the method more straightforward.

Step 1: Load Content material Into WordPress and Take a look at the REST API

Step one to the use of WordPress as a again finish is remarkably very similar to starting a WordPress website. You’ll desire a WordPress set up loaded with the entire content material you need for your site or app. This might be an lively set up or a brand new one you put up on your mission.

You’ll additionally must paintings on developing posts and pages, including media recordsdata, and no matter else your mission calls for content-wise. Mainly, you want to get the whole lot you need to have for your website online or app into WordPress, since this might be the place you arrange content material.

While you’ve were given the whole lot arrange, you’ll most likely wish to run a check to peer how the WordPress REST API works. Thankfully, you’ll be able to do that proper to your browser. Merely kind to your area adopted through wp-json/wp/v2/posts:

The JSON returned after requesting all posts via the WordPress REST API.

You must see one thing like the picture above, even if the volume of JSON that’s displayed will vary relying on how populated the website online is. You’ve now effectively used the WordPress REST API to go back the information for all of your posts. The REST API Handbook accommodates data on how to do this for other information as neatly.

To recap this step:

  1. First, we arrange a WordPress set up to function the again finish for our app/site.
  2. We created the content material we wish to show on our mission’s frontend inside WordPress as posts, pages, and so on.
  3. To look the REST API in motion, we returned the JSON for all our posts inside the browser.

As soon as you’re feeling like you could have a maintain on how all of the ones items are running in combination, you’ll be able to transfer on from the again finish of your website online to start paintings at the entrance finish.

Step 2: Set Up Your App or Web site’s Entrance Finish The use of React

Now you could have the ‘behind-the-scenes’ facets found out, you’ll wish to paintings at the a part of your app or site that customers will in truth get to peer. A well-liked direction for conducting this for WordPress customers is thru React:

The React Homepage.

For the uninitated, React is (because the tagline within the symbol above reads) a JavaScript library for construction consumer interfaces. It lets you create parts referred to as ‘components’, which turn out to be the items that make up the entrance finish of your app or site. This may come with posts, buttons, pictures, or any selection of different options and purposes.

There also are many other platforms you could wish to believe for construction your mission, so store round prior to you dedicate. The whole bits and bobs of the use of React (or identical) are past the scope of this newsletter. Then again, while you’ve settled on one way for developing your entrance finish, care for any configuration in order that you’re able to start out construction parts.

Step 3: Attach Your WordPress Again Finish to Your Entrance Finish

By means of now, you will have your WordPress again finish and your React (or different) entrance finish. Now, you simply wish to get them to speak to each other in order that the information from WordPress renders to your app or site. That is the place the WordPress REST API is available in.

Because you’ve already examined the API out, and feature noticed that it might probably go back knowledge on your posts and different content material, you understand it’s running and able to head. Subsequent you’ll wish to create parts that use the REST API to retrieve posts from WordPress and show them for your entrance finish.

You probably have minimum coding revel in, that is the place issues gets beautiful difficult. Should you’re hoping to release your app or site temporarily, you’re almost certainly hiring a developer to set it up for you. Then again, should you’re prepared to position in a while, you’ll be able to get started slowly running on parts and finding out as you move.

We’ve written about how to create a React component to retrieve all of your WordPress posts and show them in an app previously. It is advisable to use this publish as an workout to get began, or take a look at some online training courses.

While you’ve used the WordPress REST API to get your entire content material onto your entrance finish, you’ll be able to start to create extra (and an increasing number of advanced) parts, then paintings on customizing the entrance finish of your website online additional – all whilst the use of WordPress to proceed developing and managing content material.


There’s for sure a finding out curve in relation to the WordPress REST API, particularly in case you have minimum coding wisdom. Then again, while you get the hold of it, this option mean you can make bigger for your elementary basis to make use of WordPress as a again finish on your personal app or customized site.

This publish has supplied some elementary, simplified steps for the use of WordPress as a again finish. Let’s recap them temporarily:

  1. Load content material into WordPress and check the REST API.
  2. Arrange your app or site’s entrance finish the use of React.
  3. Attach your WordPress again finish for your React entrance finish.

Do you could have any questions concerning the REST API or the use of WordPress as a again finish? Ask them within the feedback phase underneath!

Article Thumbnail Symbol Jesus Sanz /

The publish How to Use WordPress as a Back End: Resources for Getting Started With the REST API gave the impression first on Elegant Themes Blog.

WordPress Web Design

[ continue ]