BP REST API Dev Chat Summary for January 14, 2016

Firstly, I’ve been told I’d better do a bit of an intro. My name’s Bronson Quick and I work for the wonderful company that is Human Made. I’ve been using WordPress since 2008 and I’ve been a core contributor. My most known open source project is Chassis, a project that Ryan McCue and I built, which is a very lightweight WP Vagrant install that uses Puppet for provisioning. In terms of BuddyPress contributions I’ve submitted PR’s back to @djpaulgibbs Achievements plugin and @boonebgorges Import From Ning plugin.

Introduction aside, after a few years of chatter and various siloed implementations of BP REST API’s we had our first offical BP REST API meeting this morning. The discussion’s purpose was to start talking about how we tackle making BP REST API and who wants to contribute.

I think the key takeaways are as follows:

  • The core BP REST API team: I will be leading the project with @modemlooper‘s help. If you’d like to contribute as well then please either reply here or drop into the #buddypress change and say Hi! @johnjamesjacoby has created a Github repo for the project.
  • Planning/Architecture: Planning how we tackle this is very important rather than diving straight into the code. As we’re “standing on the shoulders of giants” we can use the lessoned learnt from the WP REST API project and put in time at the start to plan this properly. It makes sense to plan out the data we would like returned from endpoints and how they relate to each other with _links. For example, if we’re displaying the data for the activities endpoint rather than showing a user_id we should link this to a user endpoint.
  • A “schema first” approach: The WP REST API infrastructure in core provides a schema which is used for both human readability of the endpoint data as well as data validation. This approach was recommended to be by one of the WP-API lead developers, Joe Hoyle at WCEU.
  • Implementation: The various iterations of the BP API that we’ve seen in the wild before were usually built pre-WP 4.4 this meant most of them wrapped/extended existing classes and they also used internal BuddyPress functions to get data. We think it’s going to make more sense going more low level and using the existing objects to get the data we need.
  • Test Driven Development: Ideally we’d plan an endpoint, write tests that fail then write the code for the endpoint until the tests pass. This is something that’s often talked about as being an ideal development methodology but it’s rarely practiced in the WordPress space. Tackling a project this way should mean less bugs although I do realise this could be a blocker for new contributors.
  • Privacy: This was raised as an issue. We think if we only expose the data that’s public in BP core and the XProfile components then we should be okay. Roles, capabilities and authentication will all come into play when we get to that point. I suggested perhaps having a constant once this gets into BP core to endable the BP REST API so that it’s up to the site owner or developer to enable this thus putting onus back on the site owner regarding privacy.
  • Initial Endpoints: We think it makes sense to tackle read only endpoints first (i.e. WP_REST_Server::READABLE) for the activity stream and Xprofile endpoint so that we can tackle the linking I mentioned earlier.
  • Folder Structure/Loader: We will need to work out a good structure for this designed with the intention that this “Feature Plugin” will one day land in BP Core. @modemlooper has opened an issue for that.
  • Start Small: A REST API for BuddyPress is a huge undertaking so we want to start small and add to it as we go.
  • Purpose: The question of “What’s the purpose of the BP-API REST API?” was raised.  The main purpose is all about exposing data in a RESTful way so that developers and site owners can use the data in any way albeit a plugin, mobile app or whatever else springs to mind. The other main purpose for the BP REST API is that we can use the endpoints going forward to alter some things internally in BuddyPress as in the past ” the functions throughout BuddyPress are very purpose built to solve one specific theme-side problem”.
  • WP-API: We need to keep on top of the changes to the infrastructure of WP-API going forward as we’ll need to port changes into the BP REST API. Luckily I should be able to be notified of critical changes through Joe Hoyle and Ryan McCue! 🙂
  • Readme: We need a readme.

We’d love your feedback and help!

If you weren’t able to attend the meeting and have some thoughts around this discussion and potential approach then please post a reply below or drop into #buddypress in Slack.