The WordPress community has been getting excited about the new REST API coming to the core WP installation soon. It was slated for version 4.0 but seems to have missed the last two releases, I hope it arrives soon.
In the meantime we can still get to grips with it via a plugin (the intention is that new core features will be implemented initially via a plugin before integration).
WordPress REST APIs
This isn’t the first REST API to come to WordPress. There are already a variety of other plugins available and JetPack provides access to the WordPress.com system.
So why would you chose the new version from Ryan McCue?
There are a few reasons why I am looking to work with the new API:
- Core integration. When this does eventually happen, we know that the new functionality will be maintained and available in future releases. We don’t have to worry about a 3rd party plugin breaking after a future release.
- Automattic’s JetPack should also provide this stability, but it is a cloud based system that works with WordPress.com. This could be a potential performance hit but more importantly it is a closed system.
- Extensibility. Following WordPress principles, this API can be extended by plugin authors, this allows me to develop my own plugins and routes.
REST API and bbPress
At present the plugin does not have built in bbPress specific routes, however it is possible to query custom posts. Seeing as bbPress bases its content around custom posts this means we are able to query Forums, Topics and Replies using this technique.
For example, here are the forums on nxtab.co.uk: http://www.nxtab.co.uk/wp-json/posts?type=forum.
However, as mentioned above, the new REST API is extendible, this means we can create some more specific routes / endpoints to handle typical bbPress requests. I am only aware of one attempt to do this so far and the code can be found over here. Thanks to Brent for sharing this.
Ideally I would like this built into the bbPress plugin itself once the API makes it into core WordPress, I need to look into adding a feature request!
With these custom routes we can start to run queries such as:
Bug? I don’t know if its my usage or a genuine bug but I have having a problem querying the children of all parents. So in the context of bbPress, replies are the child of a parent topic. We should be able to do something like this:
Or without using the custom routes, we should be able to do this:
Both appear to list out all replies rather than just showing me the children of the topic. This topic has just one reply, I would like to get both the topic and replies back in my response as this is what any app is going to want to display.
Has anyone else had a problem with using post_parent with the WP REST JSON API, or does anyone know what I am doing wrong?
Update: Worked it out!
bbPress Android App
I have been getting into Android development over the last year and a bbPress app seems like a great hobby project. It seems an obvious idea and I’m sure there will be many competing apps once the API takes hold but it seems like a great learning exercise.
I will be publishing updates on my progress here so if you like the idea of a dedicated app for viewing and interacting with bbPress forums then be sure to follow our RSS feed or sign up to email updates in the form at the bottom of this page.