Warning: This is NOT meant to be a JS tutorial. These are nothing more than field notes and observations. Some of this stuff may even be incorrect. This is a place for me to “think” things out as I learn. I’m just making it public because…that’s what I want to do. At this time. 🙂
I’m even working on a project right now for work that involves an endpoint, and that really helped me to understand better what they’re all about. In this project, we have a WordPress theme that includes a filtering function — users can filter a set of posts based on two different criteria. When users filter the posts, the posts meeting the criteria for that particular filter combination need to update on the screen in “real time”, without reloading the page. We need JS for the “real time” functionality, and for the posts we need data from the WordPress database.
The way we’ve set it up is (in the simplest of terms):
1. In WordPress, we use PHP to query a set of posts from the database and store it in an array.
What I have described is essentially a barebones outline of how AJAX works, I think? Maybe? Of course there are many more details and technicalities beyond what I described, but that is the gist, I think. I’m still a student so don’t quote me on any of this stuff, lol.
I did not write the endpoint in this case, my teammate did. I mostly worked on the JS script that uses the data from the endpoint and displays it on the front end, although my teammate helped a lot with that, too. 🙂 This week I made a point to study the endpoint closer, to see how it works, exactly. I feel like I’m a step closer to understanding them.
I mentioned earlier in this post that the concept of endpoints are important to understand since JS is being used for more than just adding fancy interactions to an HTML document. One example is using the WP REST API to receive all sorts of data from your WordPress site which you can display in your theme via JS. It’s similar in concept to what I described with the filter example above, but it takes it to the next level … you can create an entire theme using JS! Some of my colleagues are working on a prototype JS-powered theme called Picard, which is built using React (a framework for creating user interfaces with JS) and the WP REST API.
Before I read up on endpoints, I had difficulty understanding the REST API. Now I feel like I have built up enough basic knowledge to be able to study it further and understand what is, exactly, and what it’s doing. And also how it fits into themes like Picard. That’s a great feeling and I’m excited to keep learning. I’m also lucky to get to work with co-workers from whom I can learn.