TomTom Maps for JavaScript
    Preparing search index...

    Type Alias ServiceTemplate<Params, ApiRequest, ApiResponse, Response>

    Template interface defining the lifecycle methods for any service implementation.

    This type provides a standardized structure for implementing service calls, including request building, validation, sending, response parsing, and error handling.

    type ServiceTemplate<
        Params extends CommonServiceParams<ApiRequest, ApiResponse>,
        ApiRequest,
        ApiResponse,
        Response,
    > = {
        buildRequest: (params: Params) => ApiRequest;
        getAPIVersion?: (params?: Params) => number;
        parseResponse: (apiResponse: ApiResponse, params: Params) => Response;
        parseResponseError?: ParseResponseError<any>;
        requestValidation?: RequestValidationConfig<Params>;
        sendRequest: (
            request: ApiRequest,
            headers: TomTomHeaders,
        ) => ParsedFetchResponse<ApiResponse>;
    }

    Type Parameters

    Index

    Properties

    buildRequest: (params: Params) => ApiRequest

    Builds the API request from the provided parameters.

    Type Declaration

    getAPIVersion?: (params?: Params) => number

    Determines the API version to use for the service call.

    Type Declaration

      • (params?: Params): number
      • Parameters

        • Optionalparams: Params

          Input parameters that may influence the API version selection

        Returns number

        The API version number

    Useful for services that require a specific API version different from the global configuration. If not provided, the API version from the global or provided configuration will be used.

    parseResponse: (apiResponse: ApiResponse, params: Params) => Response

    Parses the successful API response into the expected return type.

    Type Declaration

    Transforms the raw API response into a structured format suitable for the caller.

    parseResponseError?: ParseResponseError<any>

    Parses an API error response before propagating it to the caller.

    Allows custom error handling and transformation of API errors into SDK-specific error types.

    requestValidation?: RequestValidationConfig<Params>

    Configuration for validating request parameters.

    Defines the validation schema and rules applied to request parameters before the request is built and sent.

    sendRequest: (
        request: ApiRequest,
        headers: TomTomHeaders,
    ) => ParsedFetchResponse<ApiResponse>

    Sends the constructed request to the API server.

    Type Declaration

    Handles the actual HTTP communication (e.g., GET or POST) with optional custom headers.