Pushing Related Resources Using HTTP/2

HTTP/2 allows a server to pre-emptively send (or "push") responses (along with corresponding "promised" requests) to a client in association with a previous client-initiated request. This can be useful when the server knows the client will need to have those responses available in order to fully process the response to the original request.

HTTP/2 を使用すると、サーバーは、以前にクライアントが開始した要求に関連して、応答を (対応する「約束された」要求と共に) クライアントに先制的に送信 (または「プッシュ」) できます。これは、元のリクエストへのレスポンスを完全に処理するために、クライアントがこれらのレスポンスを利用可能にする必要があることをサーバーが認識している場合に役立ちます。

RFC 7540

—RFC 7540

API Platform leverages this capability by pushing relations of a resource to clients.

API Platform は、リソースの関係をクライアントにプッシュすることで、この機能を活用します。

Note: We strongly recommend using Vulcain instead of this feature. Vulcain is faster, cleaner, more flexible, and is supported out of the box in the API Platform distribution.

注: この機能の代わりに Vulcain を使用することを強くお勧めします。

<?php
// api/src/Entity/Book.php
namespace App\Entity;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;

#[ApiResource]
class Book
{
     #[ApiProperty(push: true)]
    public Author $author;

    // ...
}

By setting the push attribute to true on a property holding a relation, API Platform will automatically add a valid Link HTTP header with the preload relation. According to the Preload W3C Candidate Recommendation, web servers and proxy servers can read this header, fetch the related resource and send it to the client using Server Push.

リレーションを保持するプロパティで push 属性を true に設定すると、API プラットフォームはプリロード リレーションを含む有効な Link HTTP ヘッダーを自動的に追加します。Preload W3C Candidate Recommendation に従って、ウェブ サーバーとプロキシ サーバーはこのヘッダーを読み取り、関連するリソースを取得し、サーバー プッシュを使用してクライアントに送信します。

With the Caddy web server (the server shipped as part of the distribution), you must add the push directive to your Caddyfile to be able to use this feature.

Caddy Web サーバー (ディストリビューションの一部として出荷されたサーバー) では、この機能を使用できるようにプッシュ ディレクティブを Caddyfile に追加する必要があります。

NGINX, Apache, Cloudflare, Fastly and Akamai honor this header.

NGINX、Apache、Cloudflare、Fastly、および Akamai は、このヘッダーを受け入れます。

Using this feature maximises HTTP cache hits for your API resources. For best performance, this feature should be used in conjunction with the built-in HTTP cache invalidation system (based on Varnish).

この機能を使用すると、API リソースの HTTP キャッシュ ヒットが最大化されます。最高のパフォーマンスを得るには、この機能を組み込みの HTTP キャッシュ無効化システム (Varnish に基づく) と組み合わせて使用​​する必要があります。