API: Link pages to API counterparts
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 30/100
調査の方向性
まず、issue で説明されている既存の API endpoint の go 関数、page の go/do 関数、および DocumentBinder のフローを追跡します。AutoApiPage 属性が page を API endpoint にどのように対応付けるか、また POST または PUT の do 関数がどのように選択されるかを定義します。API データと同等のデータを page にバインドしながら、追加の page 操作とフォーム処理も可能になれば完了です。
索引モデルが issue の本文から書いたものです。
説明
A very common web development technique is to design an API first, and then link it to the "front end" via lots of slow ajax calls.
This technique can still be achieved in WebEngine, but because WebEngine is completely server-side, this can be handled automatically.
For example, the following API endpoints can be created:
api/index- index API will list countriesapi/@country-namee.g. /morocco - list cities within countryapi/@country-name/@city-namee.g. /morocco/rabat - list places within cityapi/@country-name/@city-name/@place-namee.g. /morocco/rabat/national-zoo - show details on place
Once the API endpoints are created, the application's data can be used in other applications, but what if we then wanted to provide a web interface to the data, too?
It would make sense to have the pages follow the same URL structure:
page/indexpage/@country-namepage/@country-name/@city-namepage/@country-name/@city-name/@place-name
These pages will use HTML to structure the content, with data-bind attributes to indicate where the data should be bound.
The PHP should not need to "build" the data up again, because this is already done within the API's PHP logic files. Instead, the go function could be marked with an attribute #[AutoApiPage] or something similar. The presence of this attribute will automatically grab the data that an equivalent API call would respond with, and automatically performs a bind operation to the DocumentBinder. Pages might not have the exact same URL as their API counterparts, so the API endpoint can be passed into the attribute, like #[AutoApiPage("/@country-name/@city-name") for example.
Then, if more manipulation is required to the page, this can be done in the go function as usual.
Submitting a form on a page will trigger a do function. Hooking a do function to the AutoApiPage attribute will call it as a POST request, but if there's multiple do functions on the page - one for updating, one for creating, the HTTP method can be passed in as a parameter like #[AutoApiPage(HttpMethod::PUT)]. Using type juggling, these attribute parameters should be able to be passed in any order.
- 主要言語
- PHP
- スター
- 26
- フォーク
- 6
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
phpgt/WebEngine のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 50/100
-
Docs: missing pieces オープン
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
-
question
-
enhancement
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
phpgt/WebEngine の issue をすべて見る
似ている issue
-
Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
Automattic/safe-publish#594 ·
-
needs-triage Platform(Default)
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
HttpClient
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
symfony/symfony-docs#23092 ·
-
sync-en
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
-
sync-en
難易度 1/5 1時間未満 初心者へのやさしさ 95/100