WordPress REST API Sample JavaScript App Code

The WordPress REST API is a great tool allowing developers to create interfaces, websites and apps in any language or framework, while using WordPress data for content and settings. This is by far one of the best written APIs I have ever worked with. The API allows you to get at any data in WordPress directly through the many endpoints that are available to you.

I have written a single-page JavaScript application which creates a web page using the data from any URL you specify. This example uses jQuery, mainly for the ease of using $.get to retrieve data from the API endpoints. It also uses mustache.js for JS templating. Lastly, I used a starter Foundation template to make it look presentable.

To see this demo, click this link: WordPress REST API JavaScript Demo Code

You can also get this working directly on your computer, no need for a server, since this is just an HTML file. To run this locally, make sure you open the file /includes/app/main.js in your editor, then edit the RESTURL website value to any website you want. If you run this locally, you might have issues with https websites, so try it with a non-https site, or run it from a server.

Leave a Reply