Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

API: Link pages to API counterparts

オープン
#647 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
30/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
php
領域
api, backend, web-dev

調査の方向性

まず、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 countries
  • api/@country-name e.g. /morocco - list cities within country
  • api/@country-name/@city-name e.g. /morocco/rabat - list places within city
  • api/@country-name/@city-name/@place-name e.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/index
  • page/@country-name
  • page/@country-name/@city-name
  • page/@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 はありません

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

phpgt/WebEngine のほかの issue

phpgt/WebEngine の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。