Package com.contentstack.sdk
Class Endpoint
- java.lang.Object
-
- com.contentstack.sdk.Endpoint
-
public class Endpoint extends Object
Resolves Contentstack API endpoints for any region and service without hardcoding host strings.Resolution chain
- In-memory cache — populated on the first call and reused for the JVM lifetime (zero I/O on every subsequent call).
- Bundled
regions.json— read from the classpath resource/assets/regions.jsonthat is packaged inside the SDK jar. Works fully offline with zero latency. - 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 Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Map<String,String>getAllEndpoints(@NotNull String region)Returns all endpoints for the given region as an ordered map of service key to URL.static Map<String,String>getAllEndpoints(@NotNull String region, boolean omitHttps)Returns all endpoints for the given region, optionally stripping thehttps://scheme.static StringgetContentstackEndpoint(@NotNull String region, @NotNull String service)Returns the URL for the given region and service.static StringgetContentstackEndpoint(@NotNull String region, @NotNull String service, boolean omitHttps)Returns the URL for the given region and service, optionally stripping thehttps://scheme.
-
-
-
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 thehttps://scheme.- Parameters:
region- the region ID or aliasservice- the service keyomitHttps- whentrue, returns the bare host without thehttps://prefix- Returns:
- the URL (or bare host when
omitHttpsistrue) - 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 thehttps://scheme.- Parameters:
region- the region ID or aliasomitHttps- whentrue, returns bare hosts without thehttps://prefix- Returns:
- map of service key → URL (or bare host)
- Throws:
IllegalArgumentException- if the region is not recognised
-
-