最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugin development - What's the Right Way to get and save remote data for a Gutenberg block?

programmeradmin3浏览0评论

I'm writing a new block, where one of the pieces of input is a URL to a remote API. That remote API returns some data (in the first instance, a CSV file), which should be saved locally, and then is accessed by the front-end of the block (i.e., I have to get the name/URL of the local file to some front-end javascript).

The way I'm doing it right now is, I've implemented my own route and endpoint for the REST API, so that when the author inputs the URL in the editor, it does a PUT to my endpoint. The backend grabs the remote file from that URL, stores it locally, and returns the local file name. That response to the REST API (the local file name) is then stored in another attribute in the block.

Someone pointed out that this probably isn't correct, as I probably shouldn't be retrieving that remote data or saving anything until the post is saved. What's the Right Way to do this?

发布评论

评论列表(0)

  1. 暂无评论