前言介紹
- 這款 WordPress 外掛「WP REST API Idempotent Requests」是 2017-04-08 上架。
- 目前尚無安裝啟用數,是個很新的外掛。如有要安裝使用,建議多測試確保功能沒問題!
- 上一次更新是 2017-04-09,距離現在已有 2947 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
- 外掛最低要求 WordPress 4.7 以上版本才可以安裝。
- 尚未有人給過這款外掛評分。
- 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。
外掛協作開發者
外掛標籤
rest-api |
內容簡介
p>當遇到網路錯誤時,API 客戶端應該能夠重試請求而不會出現請求被處理了兩次的風險。
WP API Idempotence 提供對客戶端包含唯一識別該請求的穩定性關鍵的支援。如果服務器檢測到已經處理了同一個鍵的請求,或者當前正在處理,將返回初始請求的回應。
例如:
{
"title": "My Important Post",
"content": "This will only go out once!",
"status": "draft",
"idempotency_key": "1ced64e9-9537-4b7b-9919-444d9e15e201"
}
配置
唯一識別性關鍵可以在請求標頭或請求正文中傳遞。
唯一識別性關鍵的名稱可以自定義。
更改唯一識別性關鍵支援的 HTTP 方法。預設為POST、PUT、PATCH。
包括一個示範所選擇的配置的請求界面。
開發人員
該外掛包括兩個操作可修改依賴注入容器 (DIC) 並插入自定義服務。
wp_api_idempotence_initialize_container_builder 操作允許您修改依賴性注入生成器本身,
wp_api_idempotence_initialize_container 操作允許您覆蓋依賴關係。例如:
add_action( 'wp_api_idempotence_initialize_container', function( $container ) {
$container->set( '_dataStore', DI\object( 'YourName\CustomDataStore' ) );
} );
在插件底層中,該插件由DataStore、RequestHasher、ResponseSerializer和RequestPoller組成。
DataStore 主要責任是檢索或儲存穩定請求。預設情況下,請求
儲存在自定義數據庫表中。但是,可以通過實現 DataStore
介面將其替換為自定義驅動程序,例如 Redis 服務器。
RequestHasher 產生唯一的散列值,用於 WP_REST_Request 對象。此散列值是基於請求的內容,而不是對象上的 spl_object_hash 或類似物。通過實現
RequestHasher介面,可以對其進行替換。
ResponseSerializer 將 WP_REST_Response 或 WP_Error 對象轉換成字串表示形式。
預設的 JSON 序列化支援使用wp_api_idempotence_serialized_response_data和wp_api_idempotence_attach_serialized_response_data過濾器過濾序列化過程。參考src/ResponseSerializer/Filtered.php。
如果實現ResponseSerializer界面,則會整個更換序列化器。
最後,RequestPoller 類在確定有一個穩定請求正在被處理,當另一個具有相同鍵的請求到達時,會為其輪詢數據存儲點的回應。預設情況下,數據儲存庫會輪詢每秒最多 15 次以嘗試取回回應對象。如果找不到回應,則會返回代碼為 rest_duplicate_idempotency_key 的錯誤。可以通過在 DIC 中覆蓋poll.sleepSeconds 和
poll.maxQueries 來調整這個問題。如果實現RequestPoller
介面,則可完全替換RequestPoller。
貢獻
該外掛托管在
原文外掛簡介
When a network error is encountered, API clients should be able to retry a request without a risk of their request being processed twice.
WP API Idempotence adds support for clients to include an idempotency key that uniquely identifies that request. If the server detects
that a request with the same key has already been processed or is currently being processed, the response for the initial request will
be returned.
For Example:
{
"title": "My Important Post",
"content": "This will only go out once!",
"status": "draft",
"idempotency_key": "1ced64e9-9537-4b7b-9919-444d9e15e201"
}
Configuration
Idempotency key can either be passed in the request header or the request body.
The idempotency key name can be customized.
Change the HTTP methods the idempotency key is supported for. Defaults to POST, PUT, PATCH.
A sample request interface is included to demonstrate the selected configuration.
Developers
The plugin includes two actions to modify the dependency injection container (DIC) and insert custom services.
The wp_api_idempotence_initialize_container_builder action allows you to modify the Dependency Injection builder itself and
the wp_api_idempotence_initialize_container action allows you to override dependencies. For example:
add_action( 'wp_api_idempotence_initialize_container', function( $container ) {
$container->set( '_dataStore', DI\object( 'YourName\CustomDataStore' ) );
} );
Under the hood, the plugin is made up of a DataStore, RequestHasher, ResponseSerializer and RequestPoller.
The DataStore is primarily responsible for retrieving or storing an idempotent request. By default, requests
are stored in a custom database table. This could be substituted for a custom driver by implementing the DataStore
interface. For example a Redis server.
The RequestHasher produces a unique hash for a WP_REST_Request object. This hash is based off of the contents of
the request, not for the object via spl_object_hash or similar. This can also be substituted by implementing the
RequestHasher interface.
The ResponseSerializer converts a WP_REST_Response or WP_Error object back and forth from a string representation.
The default JSON serializer supports filtering the serialization process using the wp_api_idempotence_serialized_response_data
and wp_api_idempotence_attach_serialized_response_data filters. See src/ResponseSerializer/Filtered.php.
The entire serializer can be substituted by implementing the ResponseSerializer interface.
Finally, the RequestPoller class polls the data store for a response if it is determined that an idempotent request
is currently being processed when another request with the same key arrives. By default, the data store is polled
every seconds a maximum of 15 times to try and retrieve a response object. If no response is found, an error with code
rest_duplicate_idempotency_key will be returned. This can be adjusted by overwriting the poll.sleepSeconds and
poll.maxQueries in the DIC. The RequestPoller can also be entirely subsituted by implementing the RequestPoller
interface.
Contributing
This plugin is hosted on GitHub. Issues and pull requests are welcomed.
各版本下載點
- 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
- 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「WP REST API Idempotent Requests」來進行安裝。
(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。
延伸相關外掛(你可能也想知道)
WooCommerce Legacy REST API 》總結:, - 在WooCommerce 9.0版本起,Legacy REST API將不再是WooCommerce的一部分。, - 這款外掛程式在WooCommerce 9.0及以後版本中還原了已移除的Legacy RE...。
Disable REST API 》這是最全面的 WordPress REST API 存取控制外掛!, 輕鬆安裝,安裝後不需要額外設定即可使用。只需上傳並啟用,整個 REST API 將無法被一般訪客存取。, 但如...。
Make Connector 》Make 是一個視覺化平台,讓你可以在幾分鐘內設計、建立和自動化任何事情 - 從簡單的任務到複雜的工作流程。使用 Make,你可以在 WordPress 和數千個應用程式...。
WPGraphQL 》WPGraphQL 是一個免費、開源的 WordPress 外掛,為任何 WordPress 網站提供可延伸的 GraphQL schema 和 API。, 以下是一些有助於你開始使用 WPGraphQL 的連結...。
WordPress REST API Authentication 》WordPress REST API 預設是鬆散的端點,駭客可以通過這些端點遠程控制您的網站。 您不希望駭客可以透過 WordPress 登錄和 WordPress 註冊或任何其他端點來獲...。
Disable WP REST API 》這個外掛只有一個功能:禁用沒有登入 WordPress 的訪客使用 WP REST API。不需要任何設定。, 這個外掛只有 22 行短小的程式碼(少於 2KB)。因此它非常輕量、...。
WordPress REST API (Version 2) 》WordPress 正轉變成一個完整的應用程式框架,因此需要新的 API。這個專案的目的是創建一個易於使用、易於理解且經過良好測試的框架,用於創建這些 API,以及...。
Application Passwords 》⚠️ 重要提示:此外掛已合併至 WordPress 5.6 核心,不需要單獨安裝。 查看整合指南→, 使用應用程式密碼進行身份驗證,而不必直接提供用戶的密碼。相反,為每...。
WP REST API – OAuth 1.0a Server 》使用這個外掛,您可以將應用程式連接至您的 WordPress 網站,而不必透露您的密碼。, 此外掛使用 OAuth 1.0a 協議,允許委派授權,即允許應用程式使用一組次要...。
REST API Log 》這是一款針對 WordPress REST API v2 的外掛程式,可記錄 REST API 的請求和回應紀錄。, 功能包括:, , WordPress 管理頁面,用於查看和搜尋日誌條目, API 端...。
SMNTCS Disable REST API User Endpoints 》隨著 WordPress 4.7 的推出,REST API 已經成為核心的一部分。目前,每個人都可以讀取 REST API。因此,潛在的入侵者可以通過 /wp-json/wp/v2/users 檢索所有...。
REST API Toolbox 》此外掛允許調整多個 REST API 設定, , 停用 REST API, 移除 WordPress 核心端點, 需要核心端點驗證, 強制使用 SSL, WP-CLI 命令: wp rest-api-toolbox, , 在 ...。
MultiManager WP – Manage All Your WordPress Sites Easily 》總結:, 這個外掛可以幫助你自動連接你的WordPress網站到ICDSoft WordPress MultiManager工具包,在ICDSoft Account Panel中提供。WordPress MultiManager工...。
WCFM – Multivendor Marketplace REST API for WooCommerce 》WooCommerce 多供應商市場(WCFM Marketplace)- REST API 會提供您的市場網站最強大的多供應商 REST API,您將能夠使用 HTTP Rest API 請求從其他移動應用程...。
WP REST API Meta Endpoints 》, 這是一個針對文章meta資料的 REST API WordPress外掛。。