Software Engineering in WordPress and Musings on the Deep Life

WordPress REST API Example (One of Many)

With the second-half of the REST API merge confirmation coming to WordPress 4.7, it’s safe to say that there are going to be there clearly be more than one WordPress REST API example made available in the next few months.

Then again, there are examples that already exist because it’s possible to include the REST API in your project as a plugin, but I digress.

One of the neater, smaller examples that I’ve recently come across is by Brian Krogsgard.

WordPress REST API Example: By Brian Krogsgard

Not only does it show a WordPress REST API example, it shows how to use it in the context of a Rect applications.

Details on the REST API

Before actually getting into the example (and I know, that’s what you’re here for), I want to clarify the difference in what’s been available since WordPress 4.4 and what’s coming in WordPress 4.7.

So first, here’s the quick rundown of what’s been available in WordPress since 4.4:

For client authors, this doesn’t help you much right now. Hold tight, the team is working as fast as we can on the endpoints to get them ready for a future release. In the meantime, you can make sure sites you want to work with have the plugin installed, which isn’t a change from the current state.

For plugin and theme authors, you can start building new APIs immediately using the infrastructure now in core. This can start replacing your existing custom admin-ajax endpoints or other bespoke code you already have.

And here’s what’s coming in 4.7:

This infrastructure is the core of the REST API, and provides the external interface to send and receive RESTful HTTP requests. Since shipping in 4.4, the infrastructure is now used by WordPress Core for oEmbed responses, and by plugins like WooCommerce and Jetpack, enabling anyone to create their own REST API endpoints.

It’s exciting, right? And endpoints that will be exposed is significant. You can read more about that here.

Regardless, it’s important to understand the significance of the merge and how it affects those of us who make a living by building solutions on WordPress.

A WordPress REST API Example in React

Specifically, from the example mentioned, Brian states:

In an attempt to show as simple of a React app as possible, I am stealing Chris Coyier’s example that shows CodePen jobs. I wanted to show an example using WordPress post data.

And I love this approach because the goal shows something:

  • with a small amount of code,
  • and how it can practically be applied in another application.

You can see the CodePen for the example:

http://codepen.io/krogsgard/pen/NRBqPp

As mentioned it’s a simple example with enough code to show a good looking React-based application that serves as a WordPress REST API example, as well.

The WordPress REST API Plugin

With WordPress 4.7 due in December, there’s enough time to get started with simple examples like this, more complex examples, or even reading through the available documentation.

4 Comments

  1. Roger

    I am getting trouble installing API. Does it have crushed issues ?

    • Tom

      You should just be able to install the plugin and it will be ready. Without any other information, I’m not sure what else to say, though I do recommend leaving a message on the support forum.

  2. iogames

    is this working fine with latest version or not

    • Tom

      It should be – the REST API, now part of core, works with this.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© 2023 Tom McFarlin

Theme by Anders NorenUp ↑