testInvokeMethod method

Future<TestInvokeMethodResponse> testInvokeMethod({
  1. required String httpMethod,
  2. required String resourceId,
  3. required String restApiId,
  4. String? body,
  5. String? clientCertificateId,
  6. Map<String, String>? headers,
  7. Map<String, List<String>>? multiValueHeaders,
  8. String? pathWithQueryString,
  9. Map<String, String>? stageVariables,
})

Simulate the execution of a Method in your RestApi with headers, parameters, and an incoming request body.

May throw BadRequestException. May throw UnauthorizedException. May throw NotFoundException. May throw TooManyRequestsException.

Parameter httpMethod : Required Specifies a test invoke method request's HTTP method.

Parameter resourceId : Required Specifies a test invoke method request's resource ID.

Parameter restApiId : Required The string identifier of the associated RestApi.

Parameter body : The simulated request body of an incoming invocation request.

Parameter clientCertificateId : A ClientCertificate identifier to use in the test invocation. API Gateway will use the certificate when making the HTTPS request to the defined back-end endpoint.

Parameter headers : A key-value map of headers to simulate an incoming invocation request.

Parameter multiValueHeaders : The headers as a map from string to list of values to simulate an incoming invocation request.

Parameter pathWithQueryString : The URI path, including query string, of the simulated invocation request. Use this to specify path parameters and query string parameters.

Parameter stageVariables : A key-value map of stage variables to simulate an invocation on a deployed Stage.

Implementation

Future<TestInvokeMethodResponse> testInvokeMethod({
  required String httpMethod,
  required String resourceId,
  required String restApiId,
  String? body,
  String? clientCertificateId,
  Map<String, String>? headers,
  Map<String, List<String>>? multiValueHeaders,
  String? pathWithQueryString,
  Map<String, String>? stageVariables,
}) async {
  ArgumentError.checkNotNull(httpMethod, 'httpMethod');
  ArgumentError.checkNotNull(resourceId, 'resourceId');
  ArgumentError.checkNotNull(restApiId, 'restApiId');
  final $payload = <String, dynamic>{
    if (body != null) 'body': body,
    if (clientCertificateId != null)
      'clientCertificateId': clientCertificateId,
    if (headers != null) 'headers': headers,
    if (multiValueHeaders != null) 'multiValueHeaders': multiValueHeaders,
    if (pathWithQueryString != null)
      'pathWithQueryString': pathWithQueryString,
    if (stageVariables != null) 'stageVariables': stageVariables,
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'POST',
    requestUri:
        '/restapis/${Uri.encodeComponent(restApiId)}/resources/${Uri.encodeComponent(resourceId)}/methods/${Uri.encodeComponent(httpMethod)}',
    exceptionFnMap: _exceptionFns,
  );
  return TestInvokeMethodResponse.fromJson(response);
}