New here, can wp api do this?

Hello when I use Wordpress rest api as backend for my react app will it also show for example images html elements like tables and so on that I use inside my page editor (Gutenberg) on the React front end?

For example I use a wp plugin that generates a html table with data on wp frontend, will I see the same table in react frontend, will it render there I mean?

Beceuse I saw in Api docs there is also an endpoint for pages/ content

Thanks

Hi @zealmedia, welcome to the Frontity community :slight_smile:

Of course, that’s the whole point: showing the content you add in your WordPress dashboard but using React instead of PHP to create the final HTML.

So it can also replace things like Passport.js for authentication?

And what about if I decide for example on the React side to build a Todo where authenticated wp users see only their entries, I imagin thing like this won’t work beceuse it can not be saved im mysql am I right here?

You can do pretty much whatever you want. At the end of the day Frontity is a React app :slight_smile:

For authenticating with the REST API you can use any of the available methods like Application Passwords or JWT auth.

As of right now our wp-source extension doesn’t support authentication but nothing prevents you from connecting with your REST API directly, authenticate and save your data in WordPress. Then you can easily consume that data using wp-source.

Every tutorial is showing only how to fetch my posts, but I’m not interested in posts I want my to fetch my page content how do I do this please help. Thanks

Hi, @zelamedia, fetching pages is pretty much the same as fetching posts: all you have to do is to use actions.source.fetch("/your-page-url") and then, if you want to access to your page content, you would do:

const { id } = state.source.get("/your-page-url");
const page = state.source.page[id];
const { rendered } = page.content;

Note that entities are stored in state.source as they come from the WP REST API, so I guess page.content.rendered is the attribute you need.

Tell me if it works for you.

2 Likes