Skip to main content

Type-Safe Endpoints

PrismNetworkEndpoint is the foundation of PrismNetwork. Each endpoint describes a single API call — the URL, HTTP method, headers, body, and caching behavior. Typically modeled as an enum with one case per API operation.

PrismNetworkEndpoint Protocol

Protocol Definition
Only host and path are required — everything else has a default value.

Enum-Based Pattern

The recommended pattern is one enum per API domain:
ProductEndpoint.swift

HTTP Methods

PrismNetworkMethod supports all standard methods:

URL Schemes

PrismNetworkScheme supports HTTP, HTTPS, and WebSocket protocols:

Content Types

PrismNetworkHeaderType provides constants for common Content-Type values:
Header Types

Computed URL & Request

Every endpoint exposes a computed url and request built from its properties:
URL Construction
The url and request properties are throwing — they throw PrismNetworkError.invalidURL if URLComponents fails to construct a valid URL from the endpoint’s scheme, host, path, and query items.

Caching Behavior

Set cacheInterval to enable automatic response caching for GET requests:
Endpoint Caching
The PrismNetworkAdapter stores responses in URLCache with an expiration timestamp. On subsequent requests:
  1. If a cached response exists and hasn’t expired → returns cached data
  2. If cached data exists but can’t be decoded → evicts the entry and fetches fresh
  3. If no cache or expired → fetches from network and caches the result
Caching only applies to GET requests. Setting cacheInterval on POST, PUT, PATCH, or DELETE endpoints has no effect.

Timeout Configuration

Set timeoutInterval to override the default URLSession timeout:
Custom Timeout

Authentication Patterns

Add authentication headers per-endpoint:
Auth Headers

Next Steps

Network Client

Execute endpoints through PrismNetworkClient.

Caching & Retry

Advanced caching policies and retry strategies.