This page will walk you through registering a remote data block that loads data from a Zip code REST API. It will require you to commit code to a WordPress theme or plugin.
- Go to Settings > Remote Data Blocks in your WordPress admin.
- Click on the “Connect new” button.
- Choose “HTTP” from the dropdown menu as the data source type.
- Fill in the following details:
- Data Source Name: Zip Code API
- URL: https://api.zippopotam.us/us/
- If your API requires authentication, enter those details. This API does not.
- Save the data source and return the data source list.
- In the Actions column, click the three-dot menu, then “Copy UUID” to copy the data source’s UUID to your clipboard.
In code, we’ll define a query using the data source we just created. Follow the Zip code block example, but remove the data source definition. In its place, use this code to load the data source we just created by its UUID:
$data_source = HttpDataSource::from_uuid( '{{ Data source UUID }}' );