WordPress Workflow With Rest API

No Comments

Over the last decade we’ve seen the accelerating rise of dynamic JavaScript and application programming interface (API) functionality in previously static HTML web pages. In some cases, web pages are easily as robust and complicated as older, desktop counterparts. However, for a long time WordPress had not codified option for developers who wanted to bring these exciting possibilities to their WordPress sites.

That was until a small, dedicated group decided to change all that. Growing out of Google’s 2012 Summer of Code, the group now boasts scores of dedicated contributors and by WordPress 4.5 in 2016, the Rest API was potentially available to any WordPress site.

Wait... What is Rest API?

REST is acronym for REpresentational State Transfer. It is architectural style for distributed hypermedia systems ans was first presented by Roy Fielding in 2000 in his famous dissertation.

Guiding Principles of REST

  • Client–server: By separating the user interface concerns from the data storage concerns, we improve the portability of the user interface across multiple platforms and improve scalability by simplifying the server components.
  • Stateless: Each request from client to server must contain all of the information necessary to understand the request, and cannot take advantage of any stored context on the server. Session state is therefore kept entirely on the client.
  • Cacheable: Cache constraints require that the data within a response to a request be implicitly or explicitly labeled as cacheable or non-cacheable. If a response is cacheable, then a client cache is given the right to reuse that response data for later, equivalent requests.
  • Uniform interface: By applying the software engineering principle of generality to the component interface, the overall system architecture is simplified and the visibility of interactions is improved. In order to obtain a uniform interface, multiple architectural constraints are needed to guide the behavior of components. REST is defined by four interface constraints: identification of resources; manipulation of resources through representations; self-descriptive messages; and, hypermedia as the engine of application state.
  • Layered system: The layered system style allows an architecture to be composed of hierarchical layers by constraining component behavior such that each component cannot “see” beyond the immediate layer with which they are interacting.
  • Code on demand (optional): REST allows client functionality to be extended by downloading and executing code in the form of applets or scripts. This simplifies clients by reducing the number of features required to be pre-implemented.

Where can I find the API on your WordPress site?

If you are running WordPress 4.5 or later, you can see the raw output by going to:  http://yourwordpressdomain.com/wp-json

This might not be too friendly to human eyes, but it is not meant to be.  If you’d like to navigate it visually though, you can install either the JSONView browser extension for Chrome or Firefox, or for power users, Postman for Chrome.

What can I do with Rest API for WordPress?

The basic element of the Rest API in WordPress is something called a “route”.  Routes are URLs that you can use to call objects and collections (groups of objects).  If you are familiar with the core objects of WordPress, you’ll recognize many of these such as users, terms, comments and posts.

For example, if you wanted to call upon and manipulate the post data for your site, you could use this URL:

http://yourwordpressdomain.com/wp-json/wp/v2/posts

Try it on your own WordPress site and it should return 10 posts by default, each already formatted with field names (i.e. title, content, status, date, etc).  All ready for your manipulation via JavaScript!

Experiment with the read aspect of the Rest API and get comfortable with basic concepts like filtering and formatting.  Once you’re comfortable, you can explore the GET and POST functionality to manipulate this data quickly and conveniently for authoring your own plugins!

Resources

 

I'm the front-man of It's WordPress. I come from a diverse array of backgrounds, enjoying the opportunity to expand my knowledge base and skill set by re-inventing myself. I enjoy environments that focus on emerging information, technology and concepts. I put on the technical hat in my early 20s and never really looked back. I'm love technology and the internet, as well as the outdoors and avidly hike, kayak and camp every chance I get.

About Us

We can take you from concept, through design, development and deployment in one seamless process. Whether you choose a self-managed web site or need a continuing support relationship; we've got you covered.

Click to edit this heading

Request Consulation

Ready to transform your vision into a reality? Just looking to see what it takes to get the ball rolling. Tell us about your project and we can help. No spam. No obligation. Just answers.

More from our blog

See all posts

Leave a Comment

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