API Gateway examples using SDK for Java 2.x - AWS SDK for Java

You can now use the Amazon S3 Transfer Manager (Developer Preview) in the AWS SDK for Java 2.x for accelerated file transfers. Give it a try and let us know what you think! By the way, the AWS SDK for Java team is hiring software development engineers!

API Gateway examples using SDK for Java 2.x

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

Actions are code excerpts that show you how to call individual API Gateway functions.

Scenarios are code examples that show you how to accomplish a specific task by calling multiple API Gateway functions.

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 create an API Gateway REST API.

SDK for Java 2.x

public static String createAPI( ApiGatewayClient apiGateway, String restApiId, String restApiName) { try { CreateRestApiRequest request = CreateRestApiRequest.builder() .cloneFrom(restApiId) .description("Created using the Gateway Java API") .name(restApiName) .build(); CreateRestApiResponse response = apiGateway.createRestApi(request); System.out.println("The id of the new api is "+response.id()); return response.id(); } catch (ApiGatewayException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return ""; }
  • Find instructions and more code on GitHub.

  • For API details, see CreateRestApi in AWS SDK for Java 2.x API Reference.

The following code example shows how to delete an API Gateway REST API.

SDK for Java 2.x

public static void deleteAPI( ApiGatewayClient apiGateway, String restApiId) { try { DeleteRestApiRequest request = DeleteRestApiRequest.builder() .restApiId(restApiId) .build(); apiGateway.deleteRestApi(request); System.out.println("The API was successfully deleted"); } catch (ApiGatewayException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • Find instructions and more code on GitHub.

  • For API details, see DeleteRestApi in AWS SDK for Java 2.x API Reference.

The following code example shows how to delete a deployment.

SDK for Java 2.x

public static void deleteSpecificDeployment(ApiGatewayClient apiGateway, String restApiId, String deploymentId) { try { DeleteDeploymentRequest request = DeleteDeploymentRequest.builder() .restApiId(restApiId) .deploymentId(deploymentId) .build(); apiGateway.deleteDeployment(request); System.out.println("Deployment was deleted" ); } catch (ApiGatewayException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • Find instructions and more code on GitHub.

  • For API details, see DeleteDeployment in AWS SDK for Java 2.x API Reference.

The following code example shows how to deploy an API Gateway REST API.

SDK for Java 2.x

public static String createNewDeployment(ApiGatewayClient apiGateway, String restApiId, String stageName) { try { CreateDeploymentRequest request = CreateDeploymentRequest.builder() .restApiId(restApiId) .description("Created using the AWS API Gateway Java API") .stageName(stageName) .build(); CreateDeploymentResponse response = apiGateway.createDeployment(request); System.out.println("The id of the deployment is "+response.id()); return response.id(); } catch (ApiGatewayException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return "" ; }
  • Find instructions and more code on GitHub.

  • For API details, see CreateDeployment in AWS SDK for Java 2.x API Reference.