Proxy External API request in PHP from Edit.js in Block Plugin

Okay, I figured it out!

First, I created a rest endpoint in PHP.

https://github.com/bbuilds/ih-top-nurses-block/blob/main/inc/rest.php#L11

The rest point has optional parameters using regex and then in the register_rest_route() callback builds a fetch URL depending on the parameters passed to the WP-REST endpoint.

It then fires to the external API wp_remote_get($fetch_url) and dumps the data into the REST endpoint.

https://github.com/bbuilds/ih-top-nurses-block/blob/main/src/edit.js#L77

Then in my block edit function, I set up the internal rest API call using apiFetch from "@wordpress/api-fetch" using a similar buildFetch API.

Full repo: https://github.com/bbuilds/ih-top-nurses-block