makeApiEvent function

ApiGatewayEvent makeApiEvent({
  1. String body = '',
  2. bool isBase64Encoded = false,
  3. List<String> cookies = const [],
  4. Map<String, String> headers = const {},
  5. Map<String, String> pathParameters = const {},
  6. Map<String, String> stageVariables = const {},
  7. Map<String, String> queryStringParameters = const {},
})

Implementation

ApiGatewayEvent makeApiEvent({
  String body = '',
  bool isBase64Encoded = false,
  List<String> cookies = const [],
  Map<String, String> headers = const {},
  Map<String, String> pathParameters = const {},
  Map<String, String> stageVariables = const {},
  Map<String, String> queryStringParameters = const {},
}) {
  final now = DateTime.now();
  final domainPrefix = 'test';
  final domainName = 'test.my-great.app';

  return ApiGatewayEvent(
    version: '2.0',
    routeKey: r'$default',
    rawPath: '/',
    rawQueryString: '',
    cookies: cookies,
    headers: headers,
    queryStringParameters: queryStringParameters,
    requestContext: ApiGatewayRequestContext(
      accountId: randomId(),
      apiId: randomId(6),
      authorizer: <String, ApiGatewayAuthorizer>{
        'cognito': ApiGatewayAuthorizer(claims: {}, scopes: []),
      },
      domainName: domainName,
      domainPrefix: domainPrefix,
      http: <String, String>{
        "method": "POST",
        "path": "/my/path",
        "protocol": "HTTP/1.1",
        "sourceIp": "IP",
        "userAgent": "agent",
      },
      requestId: randomId(),
      routeKey: r'$default',
      stage: 'test',
      time: now,
      timeEpoch: (now.millisecondsSinceEpoch / 1000).floor(),
    ),
    body: body,
    isBase64Encoded: isBase64Encoded,
    pathParameters: pathParameters,
    stageVariables: stageVariables,
  );
}