How to Add a RESTful API to Your WordPress Site

Adding a RESTful API to your WordPress has just become the flip of a switch. Literally.

Recently, Voce Platforms – a Voce Communications company – released a plugin named Thermal API. This plugin enables any WordPress powered site to have a full RESTful API.

After a bit of toying with it, and the support of a couple of their devs, I was able to get it working.

Once you’ve installed this plugin, you have the option to change the default URL to access the API, which defaults to “wp_api” — so you would access it via example.com/wp_api/.

The next step is to start pulling data. The simpliest example is to pull data around a specific post.

example.com/wp_api/v1/posts/{post_id}

That single call would return a lot of information, including: post ID number, the post content, associated tags with names, slugs, and tag IDs, as well as all the media attached to the post.

One thing you should be careful with this plugin is security. I would personally add some sort of htaccess IP restriction rules to ensure that the API is only being called from a trusted source. You don’t necessarily want to open your entire database of posts to the world, unless that’s your intention.

As I’ve been talking to the developers of this plugin, they are quite open to feedback.

I’ve been really for a really solid WordPress API plugin and I think I’ve found it. I’m not exactly sure why it’s called “Thermal API,” but it’s a cool name, none the less.

If you’ve installed the plugin, let me know what your thoughts are in the comments.

Comments

  1. By on

    Thanks for taking a look at Thermal. Authentication and authorization are definitely features we are looking at for future versions. I’d encourage anyone wanting to suggest features (or report bugs) post an issue to the github repo (https://github.com/voceconnect/thermal-api).

    The “Thermal” name follows a pattern we started–with our Lift search plugin–for products/plugins we release having an aviation-themed name.

    Reply »

  2. By Alex on

    I’ve installed and activated the plugin on my localhost, but I’m getting a 404 when I try to use it. I’m attempting to reach: http://localhost/wp_api/v1/posts. Any suggestions?

    Reply »

    • By Jonathan Dingman on

      Did you rebuild your permalinks by going to Settings > Permalinks and clicking “update”? Are pretty permalinks working on the rest of the site?

      Reply »

    • By on

      Alex, we had an issue with version 0.6.0 so please make sure you are using version 0.6.1. Also, if you changed the Voce\Thermal\API_ROOT constant then that replaces wp_api in the URL.

      Hope this helps.

      Reply »

      • By Alex on

        Chris, thanks for the reply. I’m using 0.6.1 with no modifications.

        Reply »

        • By on

          Hi Alex,

          Can you put in an issue on github (https://github.com/voceconnect/thermal-api) and we can help you out? Please put in your PHP/WordPress verisons and if you can do a var_dump of the $_SERVER superglobal and add the output, that would be helpful.

          Thanks.

          Reply »

  3. By Jeff on

    Jonathan,

    This project is interesting. One thing I would like to see is the api provide an authorization mechanism out of the box. This way, the entire service can be secured programatically within the source code and not by messing with .htaccess.

    I looked through the documentation and it looks like a very good effort by the team at thermal-api.

    Reply »

Leave a Reply

Your email address will not be published. Required fields are marked *