createRoute method

Future<CreateRouteOutput> createRoute({
  1. required String meshName,
  2. required String routeName,
  3. required RouteSpec spec,
  4. required String virtualRouterName,
  5. String? clientToken,
})

Creates a new route that is associated with a virtual router.

You can use the prefix parameter in your route specification for path-based routing of requests. For example, if your virtual router service name is my-service.local, and you want the route to match requests to my-service.local/metrics, then your prefix should be /metrics.

If your route matches a request, you can distribute traffic to one or more target virtual nodes with relative weighting.

May throw BadRequestException. May throw ConflictException. May throw ForbiddenException. May throw InternalServerErrorException. May throw LimitExceededException. May throw NotFoundException. May throw ServiceUnavailableException. May throw TooManyRequestsException.

Parameter meshName : The name of the service mesh in which to create the route.

Parameter routeName : The name to use for the route.

Parameter spec : The route specification to apply.

Parameter virtualRouterName : The name of the virtual router in which to create the route.

Parameter clientToken : Unique, case-sensitive identifier that you provide to ensure the idempotency of the request. Up to 36 letters, numbers, hyphens, and underscores are allowed.

Implementation

Future<CreateRouteOutput> createRoute({
  required String meshName,
  required String routeName,
  required RouteSpec spec,
  required String virtualRouterName,
  String? clientToken,
}) async {
  ArgumentError.checkNotNull(meshName, 'meshName');
  _s.validateStringLength(
    'meshName',
    meshName,
    1,
    255,
    isRequired: true,
  );
  ArgumentError.checkNotNull(routeName, 'routeName');
  _s.validateStringLength(
    'routeName',
    routeName,
    1,
    255,
    isRequired: true,
  );
  ArgumentError.checkNotNull(spec, 'spec');
  ArgumentError.checkNotNull(virtualRouterName, 'virtualRouterName');
  _s.validateStringLength(
    'virtualRouterName',
    virtualRouterName,
    1,
    255,
    isRequired: true,
  );
  final $payload = <String, dynamic>{
    'routeName': routeName,
    'spec': spec,
    'clientToken': clientToken ?? _s.generateIdempotencyToken(),
  };
  final response = await _protocol.sendRaw(
    payload: $payload,
    method: 'PUT',
    requestUri:
        '/meshes/${Uri.encodeComponent(meshName)}/virtualRouter/${Uri.encodeComponent(virtualRouterName)}/routes',
    exceptionFnMap: _exceptionFns,
  );
  final $json = await _s.jsonFromResponse(response);
  return CreateRouteOutput(
    route: RouteData.fromJson($json),
  );
}