First of all, I understand that this is a plugin at current point but it is most certainly almost part of WordPress anyway. So I hope that this is not getting flagged as off-topic.

I’ve read their official docs, a lot of other articles and watched tutorial videos but Im still not getting some of the points.. This is certainly the future of WordPress, it is very handy for mobile app developement and using/sharing data between different sites but: what does it do for my site only?


Consider this:

Im currently working on the comments. I want comment section to load only when user scrolls to comment section (with -200px offset, so that there’s no delay).

  • Im going to trigger ajax call when user scrolls to that point
  • Ajax call sends some data with it, like post_id etc
  • Run WP_Comment_Query() in server
  • Send JSON data back to client with comment relations, names, content etc
  • Use JavaScript document.createElement(), innerHTML etc to create and output comments

Now.. Why would I use REST API instead? What’s the use for me? Just futureproof?

I would still need to use JavaScript to output all the data I get.. I didn’t find any good articles why or for what I should use REST API (except data transfer between sites and mobile app developement)..

7

At its current state, it is a badly engineered feature that do not have any real advantage for a competent developer.

The basic idea, as it stands at the time this answer is written, is to expose WordPress core functionality as JSON REST API. This will enable decoupling of the WordPress “business” logic from the UI and enable creating different full or partial UIs to manage and extract information from wordpress. This by itself is not a revolution, but an evolution. just a replacement of the XML-RPC API which by itself kinda streamlines the HTTP based for submission API.

As with any evolution, at each step you might ask yourself, what advantage do you get from the former state, and the answer is probably “not much”, but hopefully the steps do accumulate to a big difference.

So why the negative preface to this answer? Because my experience as software developer is that it is rarely possible to design a generic API that is actually useful without having concrete use cases to answer to. A concrete use case here can be replacing the XML-RPC API for automated wordpress management, but any front end related has to be site specific and since there is a huge performance penalty for every request sent from the client to the server you can not just aggregate use of different API to get the result you want in a way in which the users will remain happy. This means that for front end, for non trivial usage, there will still be very little difference in development effort between using the AJAX route and the REST-API route.

Tags:

Leave a Reply

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