https://github.com/richardpiazza/sessionplus
A swift request & response framework for JSON apis.
https://github.com/richardpiazza/sessionplus
http swift urlsession
Last synced: about 2 months ago
JSON representation
A swift request & response framework for JSON apis.
- Host: GitHub
- URL: https://github.com/richardpiazza/sessionplus
- Owner: richardpiazza
- License: mit
- Created: 2020-04-21T18:25:35.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2025-02-02T18:28:29.000Z (about 1 year ago)
- Last Synced: 2025-08-18T16:34:33.152Z (8 months ago)
- Topics: http, swift, urlsession
- Language: Swift
- Homepage:
- Size: 62.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# SessionPlus
A swift _request & response_ framework for JSON apis.
[](https://swiftpackageindex.com/richardpiazza/SessionPlus)
[](https://swiftpackageindex.com/richardpiazza/SessionPlus)
This package has been designed to work across multiple swift environments by utilizing conditional checks. It has been tested on Apple platforms (macOS, iOS, tvOS, watchOS), as well as Linux (Ubuntu).
## Usage
**SessionPlus** offers a default implementation (`URLSessionClient`) that allows for requesting data from a JSON api. For example:
```swift
let url = URL(string: "https://api.agify.io")!
let client = BaseURLSessionClient(baseURL: url)
let request = Get(queryItems: [URLQueryItem(name: "name", value: "bob")])
let response = try await client.request(request)
```
### Decoding
The `Client` protocol also offers extensions for automatically decoding responses to any `Decodable` type.
```swift
struct ApiResult: Decodable {
let name: String
let age: Int
let count: Int
}
let response = try await client.request(request) as ApiResult
...
let response: ApiResult = try await client.request(request)
```
## Installation
**SessionPlus** is distributed using the [Swift Package Manager](https://swift.org/package-manager).
You can add it using Xcode or by listing it as a dependency in your `Package.swift` manifest:
```swift
let package = Package(
...
dependencies: [
.package(url: "https://github.com/richardpiazza/SessionPlus.git", .upToNextMajor(from: "2.0.0")
],
...
targets: [
.target(
name: "MyPackage",
dependencies: [
.product(name: "SessionPlus", package: "SessionPlus"),
]
)
]
)
```
## Contribution
Contributions to **SessionPlus** are welcomed and encouraged! See the [Contribution Guide](CONTRIBUTING.md) for more information.