設定
API Shield Routingは、顧客が異なるパスやホストを持つ異なるバックエンドサービスにリクエストをルーティングする、統一された外部向けAPIを作成できるようにします。
You must add Source Endpoints to Endpoint Management through established methods, including uploading a schema, via API Discovery, or by adding manually, before creating a route.
To create a route, you will need the operation ID of the Source Endpoint. To find the operation ID in the dashboard:
- Log in to the Cloudflare dashboard ↗ and select your account and domain.
- Select Security > API Shield.
- Filter the endpoints to find your Source Endpoint.
- Expand the row for your Source Endpoint and note the operation ID field.
- Select the copy icon to copy the operation ID to your clipboard.
ソースエンドポイントがエンドポイント管理に追加されたら、次のAPI呼び出しを使用して、任意の操作IDに対してルートを作成および確認します。
curl --request PUT "https://api.cloudflare.com/client/v4/zones/{zoneID}/api_gateway/operations/{operationID}/route" \--header "Content-Type: application/json" \--data '{"route": "https://api.example.com/api/service"}'{ "result": { "route": "https://api.example.com/api/service" }, "success": true, "errors": [], "messages": []}curl --request GET "https://api.cloudflare.com/client/v4/zones/{zoneID}/api_gateway/operations/{operationID}/route" \--header "Content-Type: application/json"{ "result": { "route": "https://api.example.com/api/service" }, "success": true, "errors": [], "messages": []}curl --request DELETE "https://api.cloudflare.com/client/v4/zones/{zoneID}/api_gateway/operations/{operationID}/route" \--header "Content-Type: application/json"{ "result":{}, "success":true, "errors":[], "messages":[]}ソースエンドポイントにリクエストを送信した後、ターゲットエンドポイントを直接呼び出したかのようにバックエンドサービスの内容が表示されるはずです。
API Shieldが予期しない結果を返す場合は、ソースエンドポイントのホスト、メソッド、パスを確認し、ルートを確認してターゲットエンドポイントの値が正しいことを確認してください。
The Target Endpoint cannot be routed to a Worker if the route is to the same zone.
You cannot change the method of a request. For example, a GET Source Endpoint will always send a GET request to the Target Endpoint.
You must use all of the variables in the Target Endpoint that appear in the Source Endpoint. For example, routing /api/{var1}/users/{var2} to /api/users/{var2} is not allowed and will result in an error since {var1} is present in the Source Endpoint but not in the Target Endpoint.