开发WordPress REST API应用程序:入门

This article on developing a WordPress REST API app was originally published by Torque Magazine, and is reproduced here with permission.

这篇有关开发WordPress REST API应用程序的文章最初由Torque Magazine发行 ,并经许可在此处转载。

Excitement over the WordPress REST API has been building for what seems like an eternity, but we’re still pretty much at the starting gate in terms of what it’s actually going to mean for site owners and developers once it finally lands.

对WordPress REST API的兴奋一直在建立似乎是永恒的事物,但是一旦它最终登陆,对于站点所有者和开发人员实际上意味着什么,我们仍处于起步阶段。

Though I’ve written extensively about the potential implications of the REST API, I’ve been holding back on actually diving in and getting my hands dirty to date. With the REST API finally taxiing on the runway, now seemed a great time to grasp that nettle and really start digging into detail.

尽管我已经撰写了大量有关REST API 潜在影响的文章 ,但我一直坚持不懈地进行深入研究,直到现在为止。 随着REST API终于在跑道上滑行了 ,现在似乎是抓住这一荨麻并真正开始深入研究细节的好时机。

Over the course of this series, I’ll be taking the new hotness for a spin by putting together a simple JavaScript app that uses the REST API to power its content. It promises to be an intense learning experience, but one that will hopefully serve others who are coming from a non-technical background as well.

在本系列的整个过程中,我将通过组装一个使用REST API为其内容提供动力的简单JavaScript应用程序,来探索新的热点。 它有望成为一种丰富的学习经历,但也有望为其他非技术背景的人服务。

我的背景简介 (A Brief Note on My Background)

Though WordPress has long been a passion of mine, I’m a writer and entrepreneur by trade. I can’t pretend to be coming at this project from any type of serious development background. “Knows just about enough to be dangerous” would be how I’d charitably classify my coding experience to date.

尽管WordPress长期以来一直是我的爱好,但我还是一名作家和企业家。 我不能假装从任何类型的认真开发背景来从事这个项目。 到目前为止,我将如何对自己的编码经验进行慈善分类:“知道差不多危险了”。

So, this series won’t be quite the deep dive you might expect from a theming professional such as Jack Lenox, or a senior web developer such as Ramsay Lanier. It should also be no great surprise that I’m not approaching this from the point of view of an established top-tier digital agency looking to kick the tires of the latest technology.

因此,本系列不会像杰克·莱诺克斯(Jack Lenox)这样的主题专业人士或拉姆齐·拉尼尔(Ramsay Lanier)这样的高级Web开发人员所期望的那样深入。 从一家成熟的*数字代理机构寻求采用最新技术的角度来看,我没有采用这种方法也就不足为奇了。

开发WordPress REST API应用程序:入门Major agencies such as 诸如
Modern Tribe are already Modern Tribe之类的主要机构已经working with the REST API 在使用REST API

Nope, this series will be much more along the lines of an average WordPress user looking to get to grips with the next generation of the platform via a practical, exploratory project.

不,这个系列的内容将更多地与普通WordPress用户相似,他们希望通过一个实际的探索性项目来掌握下一代平台。

Hopefully that’s an approach that will also resonate with a significant percentage of other site owners out there. Put it this way – if your eyes instantly start to glaze over at the introductions of other (admittedly excellent) tutorials such as the one below, this is the series for you:

希望这是一种方法,也可以引起很多其他网站所有者的共鸣。 这样说吧–如果您的眼睛立即开始凝视其他(公认的出色)教程的介绍,例如下面的教程,那么本系列适合您:

In the following weeks, through a series of articles, I’ll explain how I’m using Node.js and Express on the backend with a GraphQL server hooked up to a MYSQL WordPress database that uses Apollo to fetch data and pipe it into React components. Don’t worry, I’ll still be using the tried and true WordPress admin interface.

在接下来的几周中,我将通过一系列文章来说明如何在GraphQL服务器上使用Node.js和Express并将其连接到使用Apollo来获取数据并将其通过管道传递到React的MYSQL WordPress数据库组件。 别担心,我仍然会使用久经考验的WordPress管理员界面。

With those caveats out of the way, let’s briefly recap why now is a great time to be really rolling up your sleeves and using the REST API in earnest.

消除了这些警告,让我们简要地回顾一下为什么现在是真正振作精神并认真使用REST API的好时机。

为什么现在是时候拥抱REST API (Why Now Is the Time to Embrace the REST API)

The launch of Calypso and Matt Mullenweg’s State of the Word address back in late 2015 made it crystal clear which way the wind is blowing in the world of WordPress at large. To put it in a nutshell, the REST API is going to be at the centre of the next stage of the platform’s future, and developers are going to have to get on board with JavaScript sooner rather than later.

早在2015年末,Calypso和Matt Mattlenweg的Word状态报告的发布就使人们很清楚地知道WordPress世界中的风向。 简而言之,REST API将成为平台未来下一阶段的中心,并且开发人员将必须早日使用JavaScript。

开发WordPress REST API应用程序:入门

We’ve already seen entire conferences devoted to exploring the implications of the REST API, and increasingly large real-world projects basing themselves around it, despite its late arrival. From Microsoft to the New York Times, blue-chip companies worldwide are chomping at the bit to really explore its power.

我们已经看到整个会议都致力于探讨REST API的含义,尽管它来迟了,但越来越多的大型现实项目围绕它而建立。 从微软到《纽约时报》 ,全世界的蓝筹公司都在争先恐后地探索其力量。

If you’re a theme or plugin developer, you can rest assured that the vast majority of your competition are already, at the very least, actively researching the topic. If you’re a site owner, you can expect the next five years or more of your site’s development to be significantly defined by the possibilities that the REST API opens up. No matter what way you look at it, now is the time to get on board this particular train.

如果您是主题或插件开发人员,则可以放心,您竞争的绝大部分已经至少正在积极地研究该主题。 如果您是网站所有者,则可以通过打开REST API的可能性对网站的未来五年或更长的发展进行重大定义。 无论您如何看待它,现在都是时候登上这列特别的火车。

我们将在本系列中做什么 (What We’ll Be Looking to Do in This Series)

In this series, we’re going to start from scratch with a local install, and use WordPress to house a collection of quotes from a great American original — Mr. Henry David Thoreau. With our words of wisdom safely stored in the WordPress back end, we’ll be looking at interacting with them via the REST API, and building out a simple JavaScript-powered front end to display them in a variety of ways using Facebook’s React library.

在本系列文章中,我们将从本地安装开始,从头开始,并使用WordPress来存放美国原著-Henry David Thoreau先生的引文集。 我们将智慧的话语安全地存储在WordPress后端中,我们将着眼于通过REST API与之进行交互,并构建一个简单JavaScript驱动的前端,以使用Facebook的React库以多种方式显示它们。

开发WordPress REST API应用程序:入门

Along the way, we’ll touch on subjects such as alternative front end solutions, integration with mobile apps, design tips and tweaks, and experimenting with third-party APIs for added functionality. By the time we’re finished, you should have a much more grounded and practical view of what the REST API is actually all about.

在此过程中,我们将涉及诸如替代前端解决方案,与移动应用程序集成,设计技巧和调整以及尝试使用第三方API以获得附加功能等主题。 待完成时,您应该对REST API的实质有了更扎实和实用的了解。

We’ll be using WordPress 4.5.3 running on a local development environment, version 2 of the REST API as a plugin, React, and a whole lot of patience and persistence to put together our finished project. Stick along for the ride and you’re sure to pick up a ton of useful info along the way!

我们将使用在本地开发环境上运行的WordPress 4.5.3 ,作为插件的REST API版本2React和大量的耐心和持久性来组合完成的项目。 坚持前进,您一定会在途中获得大量有用的信息!

结论 (Conclusion)

The tools to get cracking with the REST API already exist, it’s used in production by several major sites worldwide, and it won’t be long until it hits the mainstream WordPress world in earnest. There’s simply never been a better time to learn about it.

可以使用REST API进行**的工具已经存在,并且已被全球多个主要站点用于生产,并且直到真正引起主流WordPress世界的欢迎才出现。 从来没有比现在更好的时间来学习它。

Aimed at a relatively non-technical audience, our series on developing a REST API app from scratch will take you from zero to hero in no time at all. You won’t need a computer science degree to follow along – just a little time, patience and perseverance.

针对非技术人员,我们的系列文章从零开始开发REST API应用程序,将使您从零变成英雄。 您无需再获得计算机科学学位,只需一点时间,耐心和毅力即可。

Stay tuned for part two, in which we’ll fire up our local site, get some data into it, and start looking at basic reading and writing functionality via the REST API.

请继续关注第二部分,在第二部分中,我们将启动本地站点,获取一些数据,然后开始研究通过REST API进行的基本读写功能。

You can read the other articles in this series here.

您可以在这里阅读本系列的其他文章。

翻译自: https://www.sitepoint.com/developing-a-wordpress-rest-api-app/