json 用于连接到 REST API 的 Wordpress 插件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8439183/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 18:06:09  来源:igfitidea点击:

Wordpress plugin to connect to a REST API?

jsonwordpressapirestplugins

提问by MindJuice

Let's say I have a RESTful API running on a server somewhere, as well as a separate, but related, Wordpress site.

假设我在某个服务器上运行了一个 RESTful API,以及一个单独但相关的 Wordpress 站点。

I want to have some pages on the WP site that show data on WP pages that has been retrieved from the REST server (in JSON format), and allow the user to view and/or edit the data on WP pages.

我希望 WP 站点上的一些页面显示从 REST 服务器(以 JSON 格式)检索的 WP 页面上的数据,并允许用户查看和/或编辑 WP 页面上的数据。

For example, let's say I have, as a REST starting point, an API that returns a list of books owned by a user. I want to display the list of books, allow the user to click on a book link and go to a page that displays the details for the book.

例如,假设我有一个 API,作为 REST 的起点,它返回用户拥有的书籍列表。我想显示书籍列表,允许用户单击书籍链接并转到显示书籍详细信息的页面。

Then if the user enters "edit mode", it lets him/her edit the data and POST/PUT it back to the server via the REST API.

然后,如果用户进入“编辑模式”,它会让他/她编辑数据并通过 REST API POST/PUT 返回到服务器。

Is there any WP plugin that lets me create pages that display and edit information like this?

是否有任何 WP 插件可以让我创建显示和编辑此类信息的页面?

I would expect that for each type of entity I could enter some metadata to indicate what to expect in the JSON and how to display it for viewing or how to build the form for it (like iPhormsdoes).

我希望对于每种类型的实体,我都可以输入一些元数据来指示在 JSON 中预期的内容以及如何显示它以供查看或如何为其构建表单(如iPhorms所做的那样)。

采纳答案by MindJuice

So WordPress has some built-in support for AJAX queries, both from the admin panel and in the user-facing pages.

因此,WordPress 在管理面板和面向用户的页面中都对 AJAX 查询提供了一些内置支持。

I don't fully understand how it all works yet as I am totally new to WordPress coding, but this seems to be what I want:

我还不完全了解它是如何工作的,因为我对 WordPress 编码完全陌生,但这似乎是我想要的:

http://codex.wordpress.org/AJAX_in_Plugins

http://codex.wordpress.org/AJAX_in_Plugins

Thanks to moimikey for mentioning WP's ajax ability.

感谢 moimikey 提到 WP 的 ajax 能力。

回答by FDI

Look at this URL, it will solve your problem https://codex.wordpress.org/HTTP_API

看看这个网址,它会解决你的问题 https://codex.wordpress.org/HTTP_API

回答by Michal

I am looking for similar functionality (I want my Wordpress page to render/update data retrieved from Spring REST CRUD repository) and I couldn't find anything.

我正在寻找类似的功能(我希望我的 Wordpress 页面呈现/更新从 Spring REST CRUD 存储库检索的数据),但我找不到任何东西。

I ended up writing my own generic shortcode plugin for Spring REST data repositories, which I will be happy to share once it's completed.

我最终为 Spring REST 数据存储库编写了自己的通用短代码插件,一旦完成,我将很乐意分享。

You can also write your own shortcode plugin based on the following tutorials / blog posts, it is fairly straight-forward:

您还可以根据以下教程/博客文章编写自己的短代码插件,它非常简单:

回答by moimikey

If I understand your post correctly, perhaps this would do the trick.

如果我正确理解您的帖子,也许这可以解决问题。

http://wordpress.org/extend/plugins/json-api/

http://wordpress.org/extend/plugins/json-api/

It has 3 controllers:

它有3个控制器:

Post: create_post

帖子:create_post

Core: info get_recent_posts get_post get_page get_date_posts get_category_posts get_tag_posts get_author_posts get_search_results get_date_index get_category_index get_tag_index get_author_index get_page_index get_nonce

核心: info get_recent_posts get_post get_page get_date_posts get_category_posts get_tag_posts get_author_posts get_search_results get_date_index get_category_index get_tag_index get_author_index get_page_index get_nonce

Respond: submit_comment

回复:submit_comment