Class Endpoint


  • public class Endpoint
    extends Object
    Resolves Contentstack API endpoints for any region and service without hardcoding host strings.

    Resolution chain

    1. In-memory cache — populated on the first call and reused for the JVM lifetime (zero I/O on every subsequent call).
    2. Bundled regions.json — read from the classpath resource /assets/regions.json that is packaged inside the SDK jar. Works fully offline with zero latency.
    3. Live download — if the requested region is not present in the bundled file (e.g. Contentstack added a new region after this SDK version was released), a single HTTP request is made to "https://artifacts.contentstack.com/regions.json" to fetch the latest registry. The downloaded data replaces the in-memory cache so all subsequent lookups benefit from it. This attempt is made at most once per JVM session to avoid repeated network calls for genuinely invalid region strings.

    Region matching is case-insensitive and treats - and _ as equivalent separators, so "AZURE_NA", "azure-na", and "Azure_NA" all resolve to the same region.

    Examples:

       String url  = Endpoint.getContentstackEndpoint("eu", "contentDelivery");
       // → "https://eu-cdn.contentstack.com"
    
       String host = Endpoint.getContentstackEndpoint("eu", "contentDelivery", true);
       // → "eu-cdn.contentstack.com"
    
       Map<String, String> all = Endpoint.getAllEndpoints("azure-na");
       // → {"contentDelivery": "https://azure-na-cdn.contentstack.com", ...}
     
    • Method Detail

      • getContentstackEndpoint

        public static String getContentstackEndpoint​(@NotNull
                                                     @NotNull String region,
                                                     @NotNull
                                                     @NotNull String service)
        Returns the URL for the given region and service.
        Parameters:
        region - the region ID or alias (e.g. "na", "eu", "azure-na")
        service - the service key (e.g. "contentDelivery", "contentManagement")
        Returns:
        the full URL including https:// scheme
        Throws:
        IllegalArgumentException - if the region or service is not recognised
      • getContentstackEndpoint

        public static String getContentstackEndpoint​(@NotNull
                                                     @NotNull String region,
                                                     @NotNull
                                                     @NotNull String service,
                                                     boolean omitHttps)
        Returns the URL for the given region and service, optionally stripping the https:// scheme.
        Parameters:
        region - the region ID or alias
        service - the service key
        omitHttps - when true, returns the bare host without the https:// prefix
        Returns:
        the URL (or bare host when omitHttps is true)
        Throws:
        IllegalArgumentException - if the region or service is not recognised
      • getAllEndpoints

        public static Map<String,​String> getAllEndpoints​(@NotNull
                                                               @NotNull String region)
        Returns all endpoints for the given region as an ordered map of service key to URL.
        Parameters:
        region - the region ID or alias
        Returns:
        map of service key → URL
        Throws:
        IllegalArgumentException - if the region is not recognised
      • getAllEndpoints

        public static Map<String,​String> getAllEndpoints​(@NotNull
                                                               @NotNull String region,
                                                               boolean omitHttps)
        Returns all endpoints for the given region, optionally stripping the https:// scheme.
        Parameters:
        region - the region ID or alias
        omitHttps - when true, returns bare hosts without the https:// prefix
        Returns:
        map of service key → URL (or bare host)
        Throws:
        IllegalArgumentException - if the region is not recognised