API Gateway-Beispiele mit SDK for PHP - AWS SDK for PHP

Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.

API Gateway-Beispiele mit SDK for PHP

Die folgenden Codebeispiele zeigen Ihnen, wie Sie Aktionen durchführen und gängige Szenarien implementieren, indem Sie die AWS SDK for PHP mit API Gateway verwenden.

Aktionen sind Codeauszüge aus größeren Programmen und müssen im Kontext ausgeführt werden. Während Aktionen Ihnen zeigen, wie Sie einzelne Servicefunktionen aufrufen, können Sie Aktionen im Kontext der zugehörigen Szenarien und serviceübergreifenden Beispiele sehen.

Szenarien sind Codebeispiele, die Ihnen zeigen, wie Sie eine bestimmte Aufgabe ausführen können, indem Sie mehrere Funktionen innerhalb desselben Services aufrufen.

Jedes Beispiel enthält einen Link zu GitHub, wo Sie Anweisungen zum Einrichten und Ausführen des Codes im Kontext finden.

Themen

Aktionen

Das folgende Codebeispiel zeigt, wie Sie eine API Gateway-Basispfadzuordnung abrufen.

SDK für PHP
Anmerkung

Auf gibt es mehr GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

require 'vendor/autoload.php'; use Aws\ApiGateway\ApiGatewayClient; use Aws\Exception\AwsException; /* //////////////////////////////////////////////////////////////////////////// * Purpose: Gets the base path mapping for a custom domain name in * Amazon API Gateway. * * Prerequisites: A custom domain name in API Gateway. For more information, * see "Custom Domain Names" in the Amazon API Gateway Developer Guide. * * Inputs: * - $apiGatewayClient: An initialized AWS SDK for PHP API client for * API Gateway. * - $basePath: The base path name that callers must provide as part of the * URL after the domain name. * - $domainName: The custom domain name for the base path mapping. * * Returns: The base path mapping, if available; otherwise, the error message. * ///////////////////////////////////////////////////////////////////////// */ function getBasePathMapping($apiGatewayClient, $basePath, $domainName) { try { $result = $apiGatewayClient->getBasePathMapping([ 'basePath' => $basePath, 'domainName' => $domainName, ]); return 'The base path mapping\'s effective URI is: ' . $result['@metadata']['effectiveUri']; } catch (AwsException $e) { return 'Error: ' . $e['message']; } } function getsTheBasePathMapping() { $apiGatewayClient = new ApiGatewayClient([ 'profile' => 'default', 'region' => 'us-east-1', 'version' => '2015-07-09' ]); echo getBasePathMapping($apiGatewayClient, '(none)', 'example.com'); } // Uncomment the following line to run this code in an AWS account. // getsTheBasePathMapping();
  • Weitere API-Informationen finden Sie unter GetBasePathMapping in der APIAWS SDK for PHP -Referenz für .

Das folgende Codebeispiel zeigt, wie Sie eine API Gateway-Basispfadzuordnung auflisten.

SDK für PHP
Anmerkung

Auf gibt es mehr GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

require 'vendor/autoload.php'; use Aws\ApiGateway\ApiGatewayClient; use Aws\Exception\AwsException; /* //////////////////////////////////////////////////////////////////////////// * Purpose: Lists the base path mapping for a custom domain name in * Amazon API Gateway. * * Prerequisites: A custom domain name in API Gateway. For more information, * see "Custom Domain Names" in the Amazon API Gateway Developer Guide. * * Inputs: * - $apiGatewayClient: An initialized AWS SDK for PHP API client for * API Gateway. * - $domainName: The custom domain name for the base path mappings. * * Returns: Information about the base path mappings, if available; * otherwise, the error message. * ///////////////////////////////////////////////////////////////////////// */ function listBasePathMappings($apiGatewayClient, $domainName) { try { $result = $apiGatewayClient->getBasePathMappings([ 'domainName' => $domainName ]); return 'The base path mapping(s) effective URI is: ' . $result['@metadata']['effectiveUri']; } catch (AwsException $e) { return 'Error: ' . $e['message']; } } function listTheBasePathMappings() { $apiGatewayClient = new ApiGatewayClient([ 'profile' => 'default', 'region' => 'us-east-1', 'version' => '2015-07-09' ]); echo listBasePathMappings($apiGatewayClient, 'example.com'); } // Uncomment the following line to run this code in an AWS account. // listTheBasePathMappings();
  • Weitere API-Informationen finden Sie unter ListBasePathMappings in der APIAWS SDK for PHP -Referenz für .

Das folgende Codebeispiel zeigt, wie Sie eine API Gateway-Basispfadzuordnung aktualisieren.

SDK für PHP
Anmerkung

Auf gibt es mehr GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

require 'vendor/autoload.php'; use Aws\ApiGateway\ApiGatewayClient; use Aws\Exception\AwsException; /* //////////////////////////////////////////////////////////////////////////// * * Purpose: Updates the base path mapping for a custom domain name * in Amazon API Gateway. * * Inputs: * - $apiGatewayClient: An initialized AWS SDK for PHP API client for * API Gateway. * - $basePath: The base path name that callers must provide as part of the * URL after the domain name. * - $domainName: The custom domain name for the base path mapping. * - $patchOperations: The base path update operations to apply. * * Returns: Information about the updated base path mapping, if available; * otherwise, the error message. * ///////////////////////////////////////////////////////////////////////// */ function updateBasePathMapping( $apiGatewayClient, $basePath, $domainName, $patchOperations ) { try { $result = $apiGatewayClient->updateBasePathMapping([ 'basePath' => $basePath, 'domainName' => $domainName, 'patchOperations' => $patchOperations ]); return 'The updated base path\'s URI is: ' . $result['@metadata']['effectiveUri']; } catch (AwsException $e) { return 'Error: ' . $e['message']; } } function updateTheBasePathMapping() { $patchOperations = array([ 'op' => 'replace', 'path' => '/stage', 'value' => 'stage2' ]); $apiGatewayClient = new ApiGatewayClient([ 'profile' => 'default', 'region' => 'us-east-1', 'version' => '2015-07-09' ]); echo updateBasePathMapping( $apiGatewayClient, '(none)', 'example.com', $patchOperations ); } // Uncomment the following line to run this code in an AWS account. // updateTheBasePathMapping();
  • Weitere API-Informationen finden Sie unter UpdateBasePathMapping in der APIAWS SDK for PHP -Referenz für .