Class RestApi
Represents a REST API in Amazon API Gateway.
Implements
Inherited Members
Namespace: Amazon.CDK.AWS.APIGateway
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class RestApi : RestApiBase, IRestApi, IRestApiRef, IResourceWithPolicy, IResource, IConstruct, IDependable, IResourceWithPolicyV2, IEnvironmentAware
Syntax (vb)
Public Class RestApi Inherits RestApiBase Implements IRestApi, IRestApiRef, IResourceWithPolicy, IResource, IConstruct, IDependable, IResourceWithPolicyV2, IEnvironmentAware
Remarks
Use addResource and addMethod to configure the API model.
By default, the API will automatically be deployed and accessible from a public endpoint.
ExampleMetadata: fixture=default infused
Examples
var gateway = new Gateway(this, "MyGateway", new GatewayProps {
GatewayName = "my-gateway"
});
var api = new RestApi(this, "MyApi", new RestApiProps {
RestApiName = "my-api"
});
// Uses IAM authorization for outbound auth by default
var apiGatewayTarget = gateway.AddApiGatewayTarget("MyApiGatewayTarget", new AddApiGatewayTargetOptions {
RestApi = api,
ApiGatewayToolConfiguration = new ApiGatewayToolConfiguration {
ToolFilters = new [] { new ApiGatewayToolFilter {
FilterPath = "/pets/*",
Methods = new [] { ApiGatewayHttpMethod.GET }
} }
}
});
Synopsis
Constructors
| RestApi(Construct, string, IRestApiProps?) | Represents a REST API in Amazon API Gateway. |
Properties
| Methods | The list of methods bound to this RestApi. |
| PROPERTY_INJECTION_ID | Uniquely identifies this class. |
| RestApiId | The ID of this API Gateway RestApi. |
| RestApiRootResourceId | The resource ID of the root resource. |
| Root | Represents the root resource of this API endpoint ('/'). |
Methods
| AddModel(string, IModelOptions) | Adds a new model. |
| AddRequestValidator(string, IRequestValidatorOptions) | Adds a new request validator. |
| AddToResourcePolicy(PolicyStatement) | Adds a statement to the resource policy associated with this rest api. |
| FromRestApiAttributes(Construct, string, IRestApiAttributes) | Import an existing RestApi that can be configured with additional Methods and Resources. |
| FromRestApiId(Construct, string, string) | Import an existing RestApi. |
| IsRestApi(object) | Return whether the given object is a |
Constructors
RestApi(Construct, string, IRestApiProps?)
Represents a REST API in Amazon API Gateway.
public RestApi(Construct scope, string id, IRestApiProps? props = null)
Parameters
- scope Construct
- id string
- props IRestApiProps
Remarks
Use addResource and addMethod to configure the API model.
By default, the API will automatically be deployed and accessible from a public endpoint.
ExampleMetadata: fixture=default infused
Examples
var gateway = new Gateway(this, "MyGateway", new GatewayProps {
GatewayName = "my-gateway"
});
var api = new RestApi(this, "MyApi", new RestApiProps {
RestApiName = "my-api"
});
// Uses IAM authorization for outbound auth by default
var apiGatewayTarget = gateway.AddApiGatewayTarget("MyApiGatewayTarget", new AddApiGatewayTargetOptions {
RestApi = api,
ApiGatewayToolConfiguration = new ApiGatewayToolConfiguration {
ToolFilters = new [] { new ApiGatewayToolFilter {
FilterPath = "/pets/*",
Methods = new [] { ApiGatewayHttpMethod.GET }
} }
}
});
Properties
Methods
The list of methods bound to this RestApi.
public virtual Method[] Methods { get; }
Property Value
Method[]
Remarks
Use addResource and addMethod to configure the API model.
By default, the API will automatically be deployed and accessible from a public endpoint.
ExampleMetadata: fixture=default infused
PROPERTY_INJECTION_ID
Uniquely identifies this class.
public static string PROPERTY_INJECTION_ID { get; }
Property Value
Remarks
Use addResource and addMethod to configure the API model.
By default, the API will automatically be deployed and accessible from a public endpoint.
ExampleMetadata: fixture=default infused
RestApiId
The ID of this API Gateway RestApi.
public override string RestApiId { get; }
Property Value
Overrides
Remarks
Use addResource and addMethod to configure the API model.
By default, the API will automatically be deployed and accessible from a public endpoint.
ExampleMetadata: fixture=default infused
RestApiRootResourceId
The resource ID of the root resource.
public override string RestApiRootResourceId { get; }
Property Value
Overrides
Remarks
Use addResource and addMethod to configure the API model.
By default, the API will automatically be deployed and accessible from a public endpoint.
ExampleMetadata: fixture=default infused
Root
Represents the root resource of this API endpoint ('/').
public override IResource Root { get; }
Property Value
Overrides
Remarks
Resources and Methods are added to this resource.
Methods
AddModel(string, IModelOptions)
Adds a new model.
public virtual Model AddModel(string id, IModelOptions props)
Parameters
- id string
- props IModelOptions
Returns
Remarks
Use addResource and addMethod to configure the API model.
By default, the API will automatically be deployed and accessible from a public endpoint.
ExampleMetadata: fixture=default infused
AddRequestValidator(string, IRequestValidatorOptions)
Adds a new request validator.
public virtual RequestValidator AddRequestValidator(string id, IRequestValidatorOptions props)
Parameters
- id string
- props IRequestValidatorOptions
Returns
Remarks
Use addResource and addMethod to configure the API model.
By default, the API will automatically be deployed and accessible from a public endpoint.
ExampleMetadata: fixture=default infused
AddToResourcePolicy(PolicyStatement)
Adds a statement to the resource policy associated with this rest api.
public override IAddToResourcePolicyResult AddToResourcePolicy(PolicyStatement statement)
Parameters
- statement PolicyStatement
The policy statement to add.
Returns
Overrides
Remarks
A resource policy will be automatically created upon the first call to addToResourcePolicy.
Note that this does not work with imported rest api.
FromRestApiAttributes(Construct, string, IRestApiAttributes)
Import an existing RestApi that can be configured with additional Methods and Resources.
public static IRestApi FromRestApiAttributes(Construct scope, string id, IRestApiAttributes attrs)
Parameters
- scope Construct
- id string
- attrs IRestApiAttributes
Returns
Remarks
Use addResource and addMethod to configure the API model.
By default, the API will automatically be deployed and accessible from a public endpoint.
ExampleMetadata: fixture=default infused
FromRestApiId(Construct, string, string)
Import an existing RestApi.
public static IRestApi FromRestApiId(Construct scope, string id, string restApiId)
Parameters
Returns
Remarks
Use addResource and addMethod to configure the API model.
By default, the API will automatically be deployed and accessible from a public endpoint.
ExampleMetadata: fixture=default infused
IsRestApi(object)
Return whether the given object is a RestApi.
public static bool IsRestApi(object x)
Parameters
- x object
Returns
Remarks
Use addResource and addMethod to configure the API model.
By default, the API will automatically be deployed and accessible from a public endpoint.
ExampleMetadata: fixture=default infused