Skip to content

A Swift library for handling network communication, including HTTP requests and WebSocket connections (coming soon), with a focus on simplicity and modern Swift features.

Notifications You must be signed in to change notification settings

ReidoBoss/SwiftNetworkKit

Repository files navigation

Swift Network Kit

A modern HTTP networking library for Swift and SwiftUI, supporting all Apple platforms.

Platforms


Features

- Simple, fluent API for HTTP requests
- Built for SwiftUI and concurrency
- Codable support for request and response bodies
- Customizable headers, query parameters, and content types
- Optional base URL for convenient relative path requests
- Works on macOS, iOS, tvOS, watchOS, and visionOS


Installation

Add SwiftNetworkKit to your project using Swift Package Manager:

https://github.com/reidoboss/SwiftNetworkKit.git

Quick Start

Basic POST request example:

struct User: Encodable {
    let name: String
    let email: String
}

struct UserResponse: Decodable {
    let id: UUID
    let name: String
}
import SwiftNetworkKit

let user = User(
    name: "Stephen T. Sagarino Jr.",
    email: "stephen@stsagarino.com"
)
let url = URL(string: "http://your.api/post")!

let response = await SNK
    .request(url: url)
    .body(user)
    .post(validateBodyAs: UserResponse.self)

if let userData = response.data {
    print("User ID: \(userData.id), Name: \(userData.name)")
} else if let error = response.error {
    print("Error: \(error)")
}

POST Example same above but with Base URL

import SwiftNetworkKit

let url = URL(string: "https://your.api")!

let customSNK = SNKSession(
    urlSession: .shared,
    baseURL: url
)

let response =
    try await customSNK
    .request(path: "/post")
    .body(user)
    .post(validateBodyAs: UserResponse.self)

if let userData = response.data {
    print("User ID: \(userData.id), Name: \(userData.name)")
} else if let error = response.error {
    print("Error: \(error)")
}

Websocket

- Coming Soon


Documentation

- API Reference (coming soon)
- Examples (coming soon)
- FAQ (coming soon)

About

A Swift library for handling network communication, including HTTP requests and WebSocket connections (coming soon), with a focus on simplicity and modern Swift features.

Resources

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages