Skip to content

Can the package @wordpress/api-fetch also be used on the frontend? #38137

Answered by gziolo
ivanjeremic asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, you should be able to use @wordpress/api-fetch also on the front end. It requires some configuration but you can check how it's done in the admin here:

https://github.com/WordPress/wordpress-develop/blob/b8f97013df4fb461c72ebf7d0b5166bac15a526b/src/wp-includes/script-loader.php#L294-L323

I don't know how much of that is related to the block editor so you need to find your ideal setup.

Also is using alternatives like Axios fine?

I guess it's also fine. In particular, when you only want to perform requests for logged out users where handling for nonces would be useful.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by gziolo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
[Package] API fetch /packages/api-fetch
2 participants