Network Client
PrismNetwork provides a protocol-oriented HTTP client layer built onURLSession. Define type-safe requests, decode responses automatically, and swap implementations for testing.
Architecture
PrismNetworkClient
Protocol defining
request(on:with:) and redirect(from:). Program against this for testability.PrismNetworkAdapter
Actor-based
URLSession implementation with caching, redirect capture, and status code validation.PrismNetworkRequest
Ties an endpoint to a response type. Default decoding via
PrismEntity.Basic Usage
1. Define an Endpoint
Endpoints describe a single API call — host, path, method, headers, and body:UserEndpoint.swift
2. Define a Request
A request ties an endpoint to aDecodable response type:
UserRequest.swift
3. Execute the Request
Fetching Users
Custom Date Formatting
Pass aDateFormatter when your API returns non-standard date formats:
Custom Date Decoding
Redirect Handling
Capture redirect URLs without following them:Capture Redirect
PrismNetworkAdapter Configuration
The adapter wrapsURLSession and supports custom session configurations and caching:
Custom Adapter
Error Handling
All errors are typed asPrismNetworkError:
Handling Errors
Testing with Mock Clients
BecausePrismNetworkClient is a protocol, you can create mock implementations:
Mock Client
Next Steps
Type-Safe Endpoints
Learn the full endpoint protocol and enum-based patterns.
Caching & Retry
Add response caching and automatic retry policies.
WebSocket Client
Real-time communication from client apps.
Server HTTP Client
Make outbound HTTP requests from PrismServer.