如何使用整合fetch包裝 - AWS WAF、 AWS Firewall Manager、和 AWS Shield Advanced

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

如何使用整合fetch包裝

您可以通過更改AwsWafIntegration命名空間下的 fetch API 的常規fetch調用來使用 AWS WAF fetch包裝器。 AWS WAF 包裝器支援與標準 JavaScript fetch API 呼叫相同的所有選項,並為整合新增權杖處理。這種方法通常是整合應用程式的最簡單方法。

在包裝實現之前

下列範例清單會顯示實作AwsWafIntegrationfetch包裝函式之前的標準程式碼。

const login_response = await fetch(login_url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: login_body });
包裝實現之後

下列清單顯示了AwsWafIntegrationfetch包裝函式實作的相同程式碼。

const login_response = await AwsWafIntegration.fetch(login_url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: login_body });