API Gateway examples using SDK for PHP - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

API Gateway examples using SDK for PHP

The following code examples show you how to perform actions and implement common scenarios by using the AWS SDK for PHP with API Gateway.

Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios and cross-service examples.

Scenarios are code examples that show you how to accomplish a specific task by calling multiple functions within the same service.

Each example includes a link to GitHub, where you can find instructions on how to set up and run the code in context.

Topics

Actions

The following code example shows how to use GetBasePathMapping.

SDK for PHP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

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

The following code example shows how to use ListBasePathMappings.

SDK for PHP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

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

The following code example shows how to use UpdateBasePathMapping.

SDK for PHP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

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