Skip to main content

Advanced Features

PrismNetwork includes several advanced capabilities beyond basic HTTP: request deduplication, offline request queueing, multipart file uploads with progress, and a typed GraphQL client.

Request Deduplication

PrismRequestDeduplicator coalesces identical in-flight requests so only one network call is made per unique key. Subsequent callers receive the same result.
Deduplication
Generate deduplication keys from request properties:
Key Generation
Deduplication is ideal for screens that trigger the same API call from multiple SwiftUI views. The first caller initiates the request; subsequent callers await the same Task.

Offline Queue

PrismOfflineQueue stores failed requests when the device is offline and replays them when connectivity returns.
Offline Queue

Queued Request Properties

When autoFlush is enabled, the queue monitors network connectivity and automatically replays queued requests when the device comes back online.

Multipart Uploads

Building Multipart Form Data

PrismMultipartFormData assembles multipart/form-data request bodies:
Multipart Form Data

Upload with Progress

PrismUploadTask wraps URLSession upload with an AsyncStream of progress updates:
Upload with Progress

Complete Upload Example

Full Upload Flow

GraphQL Client

PrismGraphQLClient sends typed queries and mutations, returning decoded responses with error handling.

Setup

GraphQL Client Setup

Queries

GraphQL Query

Mutations

GraphQL Mutation
PrismGraphQLClient is an actor, making it safe to call from multiple concurrent tasks. It automatically sets the Content-Type to application/json for all requests.

Next Steps

WebSocket Client

Real-time bidirectional communication.

Network Client

Core HTTP client and request patterns.