內容目錄
前言介紹
- 這款 WordPress 外掛「GP routing – WP compatible REST API」是 2015-11-26 上架。
- 目前尚無安裝啟用數,是個很新的外掛。如有要安裝使用,建議多測試確保功能沒問題!
- 上一次更新是 2015-11-27,距離現在已有 3447 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
- 外掛最低要求 WordPress 3.0.1 以上版本才可以安裝。
- 尚未有人給過這款外掛評分。
- 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。
外掛協作開發者
外掛標籤
內容簡介
這個外掛讓開發人員可以建立 REST-ish API,可以訪問 WordPress 和其所有外掛的物件。
使用方法
安裝此外掛就像安裝其他外掛一樣。
此項目分為兩組檔案:
* index.php - 這裡可以註冊路由和/或中介層(middleware)。
* routes/ - 這裡放置您的路由。
中介層(Middleware)
中介層是在每次呼叫 API 時執行的函式,通常用於驗證參數或
在路由到達之前轉換請求,中介層的代碼結構如下:
app::middleware(function () {
做一些事情();
});
中介層適用於每個動詞,不會自動分配 $_POST 或 $_GET 給任何變數
路由(Routes)
路由是您會連接請求到根據其 HTTP 動詞連接到一個函數的地方。
路由引擎將 /api/ 所有呼叫並將斜線附加到所有請求。
GET 請求會像這樣匹配:
app::get('/testget', function($req){
return $req;
});
其中:
* app::get - 這將數據匹配為 GET 請求。
* '/testget' - 路由引擎將會尋找的路徑。
* function(){ } ... - 當路由匹配時要執行的函數。
* $req - 發送到動詞的參數。
要對此路徑做出呼叫,完整路徑會是:
http://www.mysite.com/api/testget/
斜線後總是需要。
對於所有路由的參數都會作為回調的第一個參數發送。
應在 index 檔中註冊路由,方法是將 app::routes 與路由的檔案名 (不包括副檔名) 作為參數:
app::routes('test');
所有路由都會將其返回值作為 JSON 編碼回應輸出。
所有動詞的範例
GET:
app::get(‘/testget’, function($req){
return $req;
});
POST:
app::post(‘/testpost’, function($req){
return $req;
});
DELETE:
app::delete(‘/testdelete’, function($req){
return $req;
});
PUT:
app::put(‘/testput’, function($req){
return $req;
});
巢狀路由
路由可以像這樣被巢狀:
app::delete('/admin/machines', function($req){
return $req;
});
可透過向以下發出 DELETE 以呼叫:
http://www.mysite.com/api/admin/machines/
路由和中介層的註冊
路由的代碼應該放在 "routes" 資料夾中的檔案中,然後像這樣在 index.php 檔案中 "註冊":
function gp_registerapimethods()
{
app::middleware(function () {
});
app::routes('test');
}
index.php 檔中只應存在 gp_registerapimethods 的一個實例。
中介層和路由可以有多個實例。
可以使用此調用而不是個別路由註冊以註冊路由文件夾中的所有路由:
app::routes('*');
所有範例
index.php 檔案:原文外掛簡介
Allows developers to create REST-ish API’s that have access to all of WordPress and its plug-ins objects.
Usage
Install the plug-in as any other plug-in.
Project is divided in two sets of files:
* index.php - This is where you register routes and/or middleware.
* routes/ - This is where you place your routes.
Middleware
Middlewares are functions that will be executed on every call to the API, generally used to validate parameters or
transform requests before they reach routes, code for middleware is structured like this:
app::middleware(function () {
doSomething();
});
Middlewares run for every Verb and do not automatically assign $_POST or $_GET to any variable
Routes
A route is where you would link a request to a function depending on its HTTP Verb.
The routing engine will prepend /api/ to all calls and will append a trailing slash to all requests.
A GET request would be matched like this:
app::get('/testget', function($req){
return $req;
});
In which:
* app::get - This will match up a GET request.
* '/testget' - the path the routing engine will look for.
* function(){ } ... - the function to execute when the route is matched.
* $req - parameters sent to the verb.
To make a call to this route, the full path would be:
http://www.mysite.com/api/testget/
The trailing slash is always required.
Parameters for all routes will be sent as the first parameter to the callback.
A route should be registered on the index file by placing a call to app::routes with the filename of the route (without the extension) as a parameter:
app::routes('test');
All routes output their return value as a JSON encoded response.
Samples for all verbs
GET:
app::get(‘/testget’, function($req){
return $req;
});
POST:
app::post(‘/testpost’, function($req){
return $req;
});
DELETE:
app::delete(‘/testdelete’, function($req){
return $req;
});
PUT:
app::put(‘/testput’, function($req){
return $req;
});
Nested routes
Routes can be nested like this:
app::delete('/admin/machines', function($req){
return $req;
});
Which could be called by issuing a DELETE to:
http://www.mysite.com/api/admin/machines/
Route and middleware registration
Code for the routes should be placed on a file inside the "routes" folder and then "registered" on the index.php file like this:
function gp_registerapimethods()
{
app::middleware(function () {
});
app::routes('test');
}
Only one instance of the gp_registerapimethods should exist on the index.php file.
Middleware and Routes can have as many instances as needed.
All routes inside the routes folder can be registered by doing this call instead of the individual route registration:
app::routes('*');
Sample for everything
The index.php file has the "test" route registered, and that test.php route a call for each verb which you could use as a starting point for your own services.
各版本下載點
- 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
- 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「GP routing – WP compatible REST API」來進行安裝。
(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。
延伸相關外掛(你可能也想知道)
InfiniteWP Client 》InfiniteWP 可讓使用者從自己的伺服器管理無限數量的 WordPress 網站。, 主要功能:, , 自行託管系統:位於您自己的伺服器上,完全受您控制, 一鍵更新所有網站...。
WP Consent API 》WP Consent API 是一個外掛,可以標準化插件之間同意的同意類別溝通。它需要使用 Cookie 標語插件和至少一個支援 WP Consent API 的其他插件。, , 有了這個插...。
Disable REST API 》這是最全面的 WordPress REST API 存取控制外掛!, 輕鬆安裝,安裝後不需要額外設定即可使用。只需上傳並啟用,整個 REST API 將無法被一般訪客存取。, 但如...。
Mailgun for WordPress 》Mailgun 是超過10,000名網站和應用程式開發人員信任的電子郵件自動化引擎,用於發送、接收和追踪郵件。藉助Mailgun強大的郵件API,開發人員可以更多時間建立...。
Make Connector 》Make 是一個視覺化平台,讓你可以在幾分鐘內設計、建立和自動化任何事情 - 從簡單的任務到複雜的工作流程。使用 Make,你可以在 WordPress 和數千個應用程式...。
ACF to REST API 》此 WordPress 外掛在WordPress REST API中提供了Advanced Custom Fields的端點, 詳細資訊請參閱GitHub:https://github.com/airesvsg/acf-to-rest-api/。
WordPress REST API Authentication 》WordPress REST API 預設是鬆散的端點,駭客可以通過這些端點遠程控制您的網站。 您不希望駭客可以透過 WordPress 登錄和 WordPress 註冊或任何其他端點來獲...。
Disable WP REST API 》這個外掛只有一個功能:禁用沒有登入 WordPress 的訪客使用 WP REST API。不需要任何設定。, 這個外掛只有 22 行短小的程式碼(少於 2KB)。因此它非常輕量、...。
WPGet API – Connect to any external REST API 》簡單地連接WordPress至外部API的最簡單方式。, , WPGetAPI 可輕鬆地從無限量的第三方 REST API 發送和接收資料,然後使用「Shortcode」或「Template Tag」格...。
WP REST Cache 》如果您在使用 WordPress REST API 時遇到速度問題,這個外掛將允許 WordPress 快取 REST API 的回應,使其更快。, 此外掛提供以下功能:, , 快取所有預設的 W...。
WP REST API Controller 》WP REST API Controller 外掛提供使用者易用的圖形化介面,使管理員可以切換 WordPress 核心和自訂文章類型以及分類法的可見性和端點,同時也可以自訂 API 回...。
WordPress REST API (Version 2) 》WordPress 正轉變成一個完整的應用程式框架,因此需要新的 API。這個專案的目的是創建一個易於使用、易於理解且經過良好測試的框架,用於創建這些 API,以及...。
WP REST API – OAuth 1.0a Server 》使用這個外掛,您可以將應用程式連接至您的 WordPress 網站,而不必透露您的密碼。, 此外掛使用 OAuth 1.0a 協議,允許委派授權,即允許應用程式使用一組次要...。
Contact Form to Any API 》, 「Contact form 7 to Any API」是一款強大的外掛,能夠將聯絡表單 CF7 的數據傳送至任何第三方服務。使用者可以透過這款外掛將數據發送到客戶關係管理(CRM...。
Envato Toolkit 》這個外掛包含一個三個檔案的程式庫和視覺化介面,用於驗證客戶購買代碼、獲取特定 Envato 用戶的詳細信息(國家、城市、總追隨者數量、總銷量、頭像),獲取...。