Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add network support via fetch() (#724)
## Description This pull request introduces network support to the WordPress Playground via the JavaScript fetch() API. By adding this support, the playground will have the ability to execute HTTP requests, paving the way for enhanced interactions with various APIs and services. The implementation involves creating a custom transport that delegates HTTP requests to the fetch() API. This custom transport handles network requests, thus enabling communication outside the local environment. Local testing will be a bit challenging until I deploy the updated plugin-proxy.php to playground.wordpress.net <img width="1241" alt="CleanShot 2023-10-26 at 00 29 07@2x" src="https://github.com/WordPress/wordpress-playground/assets/205419/72ae0da5-daa1-4934-9c1f-774524a0ff5c"> ## How does it work? A new Requests transport for WordPress asks JavaScript to run fetch() via `post_message_to_js()`. JavaScript runs the request and returns the response ľ see #732 for more details of that mechanism ## Testing Instructions: Testing this feature locally might be challenging until the updated plugin-proxy.php is deployed to the playground environment. Here are some basic steps to test the changes: 1. Open local Playground 2. Set up an mu-plugin that calls `wp_safe_remote_get()` to domain not on this list: ['api.wordpress.org', 'w.org', 's.w.org'] 3. Ensure that the requests are handled correctly and the expected responses are received. 4. Test various types of requests (GET, POST, etc.) and verify the correct response. 5. Check the functionality with different APIs (e.g., REST API, external APIs). cc @akirk @dmsnell @ellatrix
- Loading branch information