Skip to content
v2.277.0

MethodProps Struct ​

Example ​

ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_apigateway as apigateway } from 'aws-cdk-lib';

declare const authorizer: apigateway.Authorizer;
declare const integration: apigateway.Integration;
declare const model: apigateway.Model;
declare const requestValidator: apigateway.RequestValidator;
declare const resource: apigateway.Resource;
const methodProps: apigateway.MethodProps = {
  httpMethod: 'httpMethod',
  resource: resource,

  // the properties below are optional
  integration: integration,
  options: {
    apiKeyRequired: false,
    authorizationScopes: ['authorizationScopes'],
    authorizationType: apigateway.AuthorizationType.NONE,
    authorizer: authorizer,
    methodResponses: [{
      statusCode: 'statusCode',

      // the properties below are optional
      responseModels: {
        responseModelsKey: model,
      },
      responseParameters: {
        responseParametersKey: false,
      },
    }],
    operationName: 'operationName',
    requestModels: {
      requestModelsKey: model,
    },
    requestParameters: {
      requestParametersKey: false,
    },
    requestValidator: requestValidator,
    requestValidatorOptions: {
      requestValidatorName: 'requestValidatorName',
      validateRequestBody: false,
      validateRequestParameters: false,
    },
  },
};
python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import aws_apigateway as apigateway

# authorizer: apigateway.Authorizer
# integration: apigateway.Integration
# model: apigateway.Model
# request_validator: apigateway.RequestValidator
# resource: apigateway.Resource

method_props = apigateway.MethodProps(
    http_method="httpMethod",
    resource=resource,

    # the properties below are optional
    integration=integration,
    options=apigateway.MethodOptions(
        api_key_required=False,
        authorization_scopes=["authorizationScopes"],
        authorization_type=apigateway.AuthorizationType.NONE,
        authorizer=authorizer,
        method_responses=[apigateway.MethodResponse(
            status_code="statusCode",

            # the properties below are optional
            response_models={
                "response_models_key": model
            },
            response_parameters={
                "response_parameters_key": False
            }
        )],
        operation_name="operationName",
        request_models={
            "request_models_key": model
        },
        request_parameters={
            "request_parameters_key": False
        },
        request_validator=request_validator,
        request_validator_options=apigateway.RequestValidatorOptions(
            request_validator_name="requestValidatorName",
            validate_request_body=False,
            validate_request_parameters=False
        )
    )
)
java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.apigateway.*;

Authorizer authorizer;
Integration integration;
Model model;
RequestValidator requestValidator;
Resource resource;

MethodProps methodProps = MethodProps.builder()
        .httpMethod("httpMethod")
        .resource(resource)

        // the properties below are optional
        .integration(integration)
        .options(MethodOptions.builder()
                .apiKeyRequired(false)
                .authorizationScopes(List.of("authorizationScopes"))
                .authorizationType(AuthorizationType.NONE)
                .authorizer(authorizer)
                .methodResponses(List.of(MethodResponse.builder()
                        .statusCode("statusCode")

                        // the properties below are optional
                        .responseModels(Map.of(
                                "responseModelsKey", model))
                        .responseParameters(Map.of(
                                "responseParametersKey", false))
                        .build()))
                .operationName("operationName")
                .requestModels(Map.of(
                        "requestModelsKey", model))
                .requestParameters(Map.of(
                        "requestParametersKey", false))
                .requestValidator(requestValidator)
                .requestValidatorOptions(RequestValidatorOptions.builder()
                        .requestValidatorName("requestValidatorName")
                        .validateRequestBody(false)
                        .validateRequestParameters(false)
                        .build())
                .build())
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.APIGateway;

Authorizer authorizer;
Integration integration;
Model model;
RequestValidator requestValidator;
Resource resource;

var methodProps = new MethodProps {
    HttpMethod = "httpMethod",
    Resource = resource,

    // the properties below are optional
    Integration = integration,
    Options = new MethodOptions {
        ApiKeyRequired = false,
        AuthorizationScopes = new [] { "authorizationScopes" },
        AuthorizationType = AuthorizationType.NONE,
        Authorizer = authorizer,
        MethodResponses = new [] { new MethodResponse {
            StatusCode = "statusCode",

            // the properties below are optional
            ResponseModels = new Dictionary<string, IModel> {
                { "responseModelsKey", model }
            },
            ResponseParameters = new Dictionary<string, boolean> {
                { "responseParametersKey", false }
            }
        } },
        OperationName = "operationName",
        RequestModels = new Dictionary<string, IModel> {
            { "requestModelsKey", model }
        },
        RequestParameters = new Dictionary<string, boolean> {
            { "requestParametersKey", false }
        },
        RequestValidator = requestValidator,
        RequestValidatorOptions = new RequestValidatorOptions {
            RequestValidatorName = "requestValidatorName",
            ValidateRequestBody = false,
            ValidateRequestParameters = false
        }
    }
};
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"

var authorizer Authorizer
var integration Integration
var model Model
var requestValidator RequestValidator
var resource Resource

methodProps := &MethodProps{
	HttpMethod: jsii.String("httpMethod"),
	Resource: resource,

	// the properties below are optional
	Integration: integration,
	Options: &MethodOptions{
		ApiKeyRequired: jsii.Boolean(false),
		AuthorizationScopes: []*string{
			jsii.String("authorizationScopes"),
		},
		AuthorizationType: awscdk.Aws_apigateway.AuthorizationType_NONE,
		Authorizer: authorizer,
		MethodResponses: []MethodResponse{
			&MethodResponse{
				StatusCode: jsii.String("statusCode"),

				// the properties below are optional
				ResponseModels: map[string]IModel{
					"responseModelsKey": model,
				},
				ResponseParameters: map[string]*bool{
					"responseParametersKey": jsii.Boolean(false),
				},
			},
		},
		OperationName: jsii.String("operationName"),
		RequestModels: map[string]IModel{
			"requestModelsKey": model,
		},
		RequestParameters: map[string]*bool{
			"requestParametersKey": jsii.Boolean(false),
		},
		RequestValidator: requestValidator,
		RequestValidatorOptions: &RequestValidatorOptions{
			RequestValidatorName: jsii.String("requestValidatorName"),
			ValidateRequestBody: jsii.Boolean(false),
			ValidateRequestParameters: jsii.Boolean(false),
		},
	},
}

Properties ​

httpMethodstringhttp_methodstrhttpMethodStringHttpMethodstringHttpMethod*string required #
The HTTP method ("GET", "POST", "PUT", ...) that clients use to call this method.
integrationoptionalIntegrationintegrationoptionalIntegrationintegrationoptionalIntegrationIntegrationoptionalIntegrationIntegrationoptionalIntegration #
The backend system that the method calls when it receives a request.

Default: a new MockIntegration.

optionsoptionalMethodOptionsoptionsoptionalMethodOptionsoptionsoptionalMethodOptionsOptionsoptionalMethodOptionsOptionsoptionalMethodOptions #
Method options.

Default: No options.

resourceIResourceresourceIResourceresourceIResourceResourceIResourceResourceIResource required #
The resource this method is associated with.

For root resource methods, specify the RestApi object.