PutMethod - Amazon API Gateway

PutMethod

Add a method to an existing Resource resource.

Request Syntax

PUT /restapis/restapi_id/resources/resource_id/methods/http_method HTTP/1.1 Content-type: application/json { "apiKeyRequired": boolean, "authorizationScopes": [ "string" ], "authorizationType": "string", "authorizerId": "string", "operationName": "string", "requestModels": { "string" : "string" }, "requestParameters": { "string" : boolean }, "requestValidatorId": "string" }

URI Request Parameters

The request uses the following URI parameters.

http_method

Specifies the method request's HTTP method type.

Required: Yes

resource_id

The Resource identifier for the new Method resource.

Required: Yes

restapi_id

The string identifier of the associated RestApi.

Required: Yes

Request Body

The request accepts the following data in JSON format.

apiKeyRequired

Specifies whether the method required a valid ApiKey.

Type: Boolean

Required: No

authorizationScopes

A list of authorization scopes configured on the method. The scopes are used with a COGNITO_USER_POOLS authorizer to authorize the method invocation. The authorization works by matching the method scopes against the scopes parsed from the access token in the incoming request. The method invocation is authorized if any method scopes matches a claimed scope in the access token. Otherwise, the invocation is not authorized. When the method scope is configured, the client must provide an access token instead of an identity token for authorization purposes.

Type: Array of strings

Required: No

authorizationType

The method's authorization type. Valid values are NONE for open access, AWS_IAM for using AWS IAM permissions, CUSTOM for using a custom authorizer, or COGNITO_USER_POOLS for using a Cognito user pool.

Type: String

Required: Yes

authorizerId

Specifies the identifier of an Authorizer to use on this Method, if the type is CUSTOM or COGNITO_USER_POOLS. The authorizer identifier is generated by API Gateway when you created the authorizer.

Type: String

Required: No

operationName

A human-friendly operation identifier for the method. For example, you can assign the operationName of ListPets for the GET /pets method in the PetStore example.

Type: String

Required: No

requestModels

Specifies the Model resources used for the request's content type. Request models are represented as a key/value map, with a content type as the key and a Model name as the value.

Type: String to string map

Required: No

requestParameters

A key-value map defining required or optional method request parameters that can be accepted by API Gateway. A key defines a method request parameter name matching the pattern of method.request.{location}.{name}, where location is querystring, path, or header and name is a valid and unique parameter name. The value associated with the key is a Boolean flag indicating whether the parameter is required (true) or optional (false). The method request parameter names defined here are available in Integration to be mapped to integration request parameters or body-mapping templates.

Type: String to boolean map

Required: No

requestValidatorId

The identifier of a RequestValidator for validating the method request.

Type: String

Required: No

Response Syntax

HTTP/1.1 201 Content-type: application/json { "apiKeyRequired": boolean, "authorizationScopes": [ "string" ], "authorizationType": "string", "authorizerId": "string", "httpMethod": "string", "methodIntegration": { "cacheKeyParameters": [ "string" ], "cacheNamespace": "string", "connectionId": "string", "connectionType": "string", "contentHandling": "string", "credentials": "string", "httpMethod": "string", "integrationResponses": { "string" : { "contentHandling": "string", "responseParameters": { "string" : "string" }, "responseTemplates": { "string" : "string" }, "selectionPattern": "string", "statusCode": "string" } }, "passthroughBehavior": "string", "requestParameters": { "string" : "string" }, "requestTemplates": { "string" : "string" }, "timeoutInMillis": number, "tlsConfig": { "insecureSkipVerification": boolean }, "type": "string", "uri": "string" }, "methodResponses": { "string" : { "responseModels": { "string" : "string" }, "responseParameters": { "string" : boolean }, "statusCode": "string" } }, "operationName": "string", "requestModels": { "string" : "string" }, "requestParameters": { "string" : boolean }, "requestValidatorId": "string" }

Response Elements

If the action is successful, the service sends back an HTTP 201 response.

The following data is returned in JSON format by the service.

apiKeyRequired

A boolean flag specifying whether a valid ApiKey is required to invoke this method.

Type: Boolean

authorizationScopes

A list of authorization scopes configured on the method. The scopes are used with a COGNITO_USER_POOLS authorizer to authorize the method invocation. The authorization works by matching the method scopes against the scopes parsed from the access token in the incoming request. The method invocation is authorized if any method scopes matches a claimed scope in the access token. Otherwise, the invocation is not authorized. When the method scope is configured, the client must provide an access token instead of an identity token for authorization purposes.

Type: Array of strings

authorizationType

The method's authorization type. Valid values are NONE for open access, AWS_IAM for using AWS IAM permissions, CUSTOM for using a custom authorizer, or COGNITO_USER_POOLS for using a Cognito user pool.

Type: String

authorizerId

The identifier of an Authorizer to use on this method. The authorizationType must be CUSTOM.

Type: String

httpMethod

The method's HTTP verb.

Type: String

methodIntegration

Gets the method's integration responsible for passing the client-submitted request to the back end and performing necessary transformations to make the request compliant with the back end.

Type: Integration object

methodResponses

Gets a method response associated with a given HTTP status code.

Type: String to MethodResponse object map

operationName

A human-friendly operation identifier for the method. For example, you can assign the operationName of ListPets for the GET /pets method in the PetStore example.

Type: String

requestModels

A key-value map specifying data schemas, represented by Model resources, (as the mapped value) of the request payloads of given content types (as the mapping key).

Type: String to string map

requestParameters

A key-value map defining required or optional method request parameters that can be accepted by API Gateway. A key is a method request parameter name matching the pattern of method.request.{location}.{name}, where location is querystring, path, or header and name is a valid and unique parameter name. The value associated with the key is a Boolean flag indicating whether the parameter is required (true) or optional (false). The method request parameter names defined here are available in Integration to be mapped to integration request parameters or templates.

Type: String to boolean map

requestValidatorId

The identifier of a RequestValidator for request validation.

Type: String

Errors

For information about the errors that are common to all actions, see Common Errors.

BadRequestException

The submitted request is not valid, for example, the input is incomplete or incorrect. See the accompanying error message for details.

HTTP Status Code: 400

ConflictException

The request configuration has conflicts. For details, see the accompanying error message.

HTTP Status Code: 409

LimitExceededException

The request exceeded the rate limit. Retry after the specified time period.

HTTP Status Code: 429

NotFoundException

The requested resource is not found. Make sure that the request URI is correct.

HTTP Status Code: 404

TooManyRequestsException

The request has reached its throttling limit. Retry after the specified time period.

HTTP Status Code: 429

UnauthorizedException

The request is denied because the caller has insufficient permissions.

HTTP Status Code: 401

Examples

Create a GET method on an API's root resource

This example illustrates one usage of PutMethod.

Sample Request

PUT /restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET HTTP/1.1 Content-Type: application/json Host: apigateway.us-east-1.amazonaws.com X-Amz-Date: 20160602T180831Z Authorization: AWS4-HMAC-SHA256 Credential={access_key_ID}/20160602/us-east-1/apigateway/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date, Signature={sig4_hash} { "authorizationType" : "NONE" }

Sample Response

{ "_links": { "curies": [ ... ], "self": { "href": "/restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET", "name": "GET", "title": "GET" }, "integration:put": { "href": "/restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET/integration" }, "method:delete": { "href": "/restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET" }, "method:update": { "href": "/restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET" }, "methodresponse:put": { "href": "/restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET/responses/{status_code}", "templated": true } }, "apiKeyRequired": false, "authorizationType": "NONE", "httpMethod": "GET" }

See Also

For more information about using this API in one of the language-specific AWS SDKs, see the following: