# WebSocketMockIntegrationProps

Props for Mock type integration for a WebSocket Api.

Used as props by: [WebSocketMockIntegration](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigatewayv2_integrations.WebSocketMockIntegration.html)

- Source: [`aws-apigatewayv2-integrations/lib/websocket/mock.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-apigatewayv2-integrations/lib/websocket/mock.ts#L13)
- Type last changed: v2.176.0 · 15 Jan 2025

## Example

TypeScript:

```ts
import { WebSocketMockIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations';

const webSocketApi = new apigwv2.WebSocketApi(this, 'mywsapi');
new apigwv2.WebSocketStage(this, 'mystage', {
  webSocketApi,
  stageName: 'dev',
  autoDeploy: true,
});

webSocketApi.addRoute('sendMessage', {
  integration: new WebSocketMockIntegration('DefaultIntegration', {
    requestTemplates: { 'application/json': JSON.stringify({ statusCode: 200 }) },
    templateSelectionExpression: '\\$default',
  }),
  returnResponse: true,
});
```

Python:

```python
from aws_cdk.aws_apigatewayv2_integrations import WebSocketMockIntegration

web_socket_api = apigwv2.WebSocketApi(self, "mywsapi")
apigwv2.WebSocketStage(self, "mystage",
    web_socket_api=web_socket_api,
    stage_name="dev",
    auto_deploy=True
)

web_socket_api.add_route("sendMessage",
    integration=WebSocketMockIntegration("DefaultIntegration",
        request_templates={"application/json": JSON.stringify({"status_code": 200})},
        template_selection_expression="\\$default"
    ),
    return_response=True
)
```

Java:

```java
import software.amazon.awscdk.aws_apigatewayv2_integrations.WebSocketMockIntegration;

WebSocketApi webSocketApi = new WebSocketApi(this, "mywsapi");
WebSocketStage.Builder.create(this, "mystage")
        .webSocketApi(webSocketApi)
        .stageName("dev")
        .autoDeploy(true)
        .build();

webSocketApi.addRoute("sendMessage", WebSocketRouteOptions.builder()
        .integration(WebSocketMockIntegration.Builder.create("DefaultIntegration")
                .requestTemplates(Map.of("application/json", JSON.stringify(Map.of("statusCode", 200))))
                .templateSelectionExpression("\\$default")
                .build())
        .returnResponse(true)
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AwsApigatewayv2Integrations;

var webSocketApi = new WebSocketApi(this, "mywsapi");
new WebSocketStage(this, "mystage", new WebSocketStageProps {
    WebSocketApi = webSocketApi,
    StageName = "dev",
    AutoDeploy = true
});

webSocketApi.AddRoute("sendMessage", new WebSocketRouteOptions {
    Integration = new WebSocketMockIntegration("DefaultIntegration", new WebSocketMockIntegrationProps {
        RequestTemplates = new Dictionary<string, string> { { "application/json", JSON.Stringify(new Dictionary<string, int> { { "statusCode", 200 } }) } },
        TemplateSelectionExpression = "\\$default"
    }),
    ReturnResponse = true
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"

webSocketApi := apigwv2.NewWebSocketApi(this, jsii.String("mywsapi"))
apigwv2.NewWebSocketStage(this, jsii.String("mystage"), &WebSocketStageProps{
	WebSocketApi: WebSocketApi,
	StageName: jsii.String("dev"),
	AutoDeploy: jsii.Boolean(true),
})

webSocketApi.AddRoute(jsii.String("sendMessage"), &WebSocketRouteOptions{
	Integration: awscdk.NewWebSocketMockIntegration(jsii.String("DefaultIntegration"), &WebSocketMockIntegrationProps{
		RequestTemplates: map[string]*string{
			"application/json": JSON.stringify(map[string]*f64{
				"statusCode": jsii.Number(200),
			}),
		},
		TemplateSelectionExpression: jsii.String("\\$default"),
	}),
	ReturnResponse: jsii.Boolean(true),
})
```

## Properties

- `requestTemplates`: { [key: string]: string } — A map of Apache Velocity templates that are applied on the request payload.

  **Default:** No request template provided to the integration.

  ```
    { "application/json": "{ \"statusCode\": 200 }" }
  ```

- `templateSelectionExpression`: string — The template selection expression for the integration.

  **Default:** No template selection expression provided.
