I’ve been playing with WordPress REST APIs lately and found out that very little information is available about default endpoints and even less: about modifying them or creating you own. Especially when it comes to adding things in you DB and working with REST API responses afterwards.
One thing that cost me half an hour was reading those responses in the first place. For example, when you add something in a database, a response comes and it may look like this:
Now, let’s say you want to use this highly valuable piece of information in your new shiny React Application on a WordPress page. First thing I did was go to that async function and add return response
. Which returned exactly this:
Where is the data, you ask? Well, it ain’t here. To be able to read in JS it you have to use return response.json
.
Now we’re talking.