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 … Read more

Fetching custom post type without knowing post type (REST API)

You could create a generic REST API endpoint that just accepted a post ID. I’ve used the default WP_REST_Posts_Controller to handle some standard checks and format the response: add_action( ‘rest_api_init’, function () { register_rest_route( ‘wpse/406874’, ‘post_data/(?P<id>\d+)’, [ ‘methods’ => WP_REST_Server::READABLE, ‘permission_callback’ => ‘__return_true’, ‘callback’ => function ( WP_REST_Request $request ) { $id = (int) $request[‘id’]; … Read more