Esempi di API Gateway che utilizzano SDK for PHP - AWS SDK for PHP

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Esempi di API Gateway che utilizzano SDK for PHP

I seguenti esempi di codice mostrano come eseguire azioni e implementare scenari comuni utilizzando AWS SDK for PHP with API Gateway.

Le operazioni sono estratti di codice da programmi più grandi e devono essere eseguite nel contesto. Sebbene le operazioni mostrino come richiamare le singole funzioni del servizio, è possibile visualizzarle contestualizzate negli scenari correlati e negli esempi tra servizi.

Scenari: esempi di codice che mostrano come eseguire un'attività specifica richiamando più funzioni all'interno dello stesso servizio.

Ogni esempio include un collegamento a GitHub, dove è possibile trovare istruzioni su come configurare ed eseguire il codice nel contesto.

Argomenti

Azioni

Il seguente esempio di codice mostra come ottenere una mappatura del percorso di base dell'API Gateway.

SDK per PHP
Nota

C'è altro su. GitHub Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS.

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();
  • Per i dettagli sull'API, consulta la GetBasePathMappingsezione AWS SDK for PHP API Reference.

Il seguente esempio di codice mostra come elencare una mappatura del percorso di base dell'API Gateway.

SDK per PHP
Nota

C'è altro su. GitHub Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS.

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();

Il seguente esempio di codice mostra come aggiornare una mappatura del percorso di base dell'API Gateway.

SDK per PHP
Nota

C'è altro su. GitHub Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS.

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();