Book Image

Learning WordPress REST API

By : Sufyan bin Uzayr, Mathew Rooney
Book Image

Learning WordPress REST API

By: Sufyan bin Uzayr, Mathew Rooney

Overview of this book

The WordPress REST API is a recent innovation that has the potential to unlock several new opportunities for WordPress developers. It can help you integrate with technologies outside of WordPress, as well as offer great flexibility when developing themes and plugins for WordPress. As such, the REST API can make developers’ lives easier. The book begins by covering the basics of the REST API and how it can be used along with WordPress. Learn how the REST API interacts with WordPress, allowing you to copy posts and modify post metadata. Move on to get an understanding of taxonomies and user roles are in WordPress and how to use them with the WordPress REST API. Next, find out how to edit and process forms with AJAX and how to create custom routes and functions. You will create a fully-functional single page web app using a WordPress site and the REST API. Lastly, you will see how to deal with the REST API in future versions and will use it to interact it with third-party services. By the end of the book, you will be able to work with the WordPress REST API to build web applications.
Table of Contents (16 chapters)
Learning WordPress REST API
Credits
About the Authors
Acknowledgments
About the Reviewer
www.PacktPub.com
Preface

Preface

The REST API is the next big thing in the world of WordPress development. Ever since its inception, it has been gaining popularity, and more and more developers are turning towards it.

Of course, the REST API comes with numerous benefits, such as the ability to interact with third-party platforms and apps. Have an application coded in Ruby and want to interact with a WordPress site based on PHP? The REST API is here to help you!

This book will help you get started with the REST API for WordPress. You will learn the basics as well as the advanced details of this new API so that you can use it in your projects.

What this book covers

Chapter 1, Getting Started with REST API, gives you an overview of what the REST API is, how it functions, and all that it is capable of doing. You will also find information about other platforms if you are new to WordPress.

Chapter 2, Interacting with REST API in WordPress, is where you will learn the basics of the REST API in WordPress. General POST and GET commands shall be covered here.

Chapter 3, Working with Taxonomies and Users with REST API, moves to taxonomies such as categories and tags. Users and user roles will also be covered.

Chapter 4, Working with Forms Using REST API, will show you how the REST API can be used to work with custom forms for your WP platform. This chapter will teach you how to get the most out of it.

Chapter 5, Custom Routes in WordPress REST API, progresses beyond default roles and teaches you how to add and work with custom routes using the REST API.

Chapter 6, Creating a Simple Web App Using WordPress REST API, is where you learn how to create a web app. Plus, you will also learn how to pass commands to your web app.

Chapter 7, Mastering REST API for Your Projects, is where you will learn how to master the REST API for your projects. Obviously, this chapter requires that you have a working knowledge of the REST API, as well as experience with WordPress development.

Chapter 8, WordPress REST API in Practice, teaches you the practical aspects of the WP REST API and its development.

Chapter 9, Summing It Up, wraps up our journey with the WordPress REST API. We will have a recap of all that we have learned so far and an overview of what the REST API can do for us.

What you need for this book

Obviously, you will need a working installation of WordPress to begin with. The latest version of WordPress is recommended so that you do not miss out on security updates.

You will also need to install and activate the WordPress REST API plugin on your site. Free download and installation instructions are here: https://wordpress.org/plugins/rest-api/.

At least PHP 5.4 or higher is recommended. The latest supported version of MySQL is required as well, and enhancements such as MariaDB are also allowed.

You can run WP on a generic LAMP or WAMP stack. For further instructions, consider reading the WordPress documentation.

Who this book is for

This book is for WordPress developers and designers who want to get a complete practical understanding of the WordPress REST API and leverage it to create fully featured web apps.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "HTTP requests in JavaScript require the XMLHttpRequest object."

A block of code is set as follows:

require 'net/http'
url = 'http://www.example.com/database/1191'
resp = Net::HTTP.get_response(URI.parse(url))
resp_text = resp.body

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

require 'net/http'
url = 'http://www.example.com/database/1191'
resp = Net::HTTP.get_response(URI.parse(url))
resp_text = resp.body

Any command-line input or output is written as follows:

$url = "http://www.example.com/database/1191";
$response = file_get_contents($url);
echo $response;

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Hit Preview link in the pane and you will see your remote WordPress site in the panel."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.

  2. Hover the mouse pointer on the SUPPORT tab at the top.

  3. Click on Code Downloads & Errata.

  4. Enter the name of the book in the Search box.

  5. Select the book for which you're looking to download the code files.

  6. Choose from the drop-down menu where you purchased this book from.

  7. Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows

  • Zipeg / iZip / UnRarX for Mac

  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Learning-WordPress-REST-API. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at [email protected] with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.