https://github.com/nissaba/easyrestclient
Lightweight, protocol-oriented Swift framework for easy REST API communication. Supports Codable requests, customizable headers, query parameters, and binary uploads with Swift Package Manager (SPM) support.
https://github.com/nissaba/easyrestclient
api-client ios macos networking rest-api swfit
Last synced: about 1 year ago
JSON representation
Lightweight, protocol-oriented Swift framework for easy REST API communication. Supports Codable requests, customizable headers, query parameters, and binary uploads with Swift Package Manager (SPM) support.
- Host: GitHub
- URL: https://github.com/nissaba/easyrestclient
- Owner: nissaba
- License: mit
- Created: 2025-04-28T23:28:40.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-29T15:24:25.000Z (about 1 year ago)
- Last Synced: 2025-04-29T15:58:51.603Z (about 1 year ago)
- Topics: api-client, ios, macos, networking, rest-api, swfit
- Language: Swift
- Homepage:
- Size: 47.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# EazyRestClient
    
## Features
- Protocol-based requests with `EazyRestRequest`
- Codable support for automatic encoding/decoding
- Default headers (`Accept` & `Content-Type`)
- Optional authorization token
- Query parameters and body data support
- URLSession under the hood
- Callback and Swift Concurrency (`async/await`) APIs
## Installation
Add to your `Package.swift`:
```swift
.package(url: "https://github.com/nissaba/EasyRestClient.git", from: "1.1.0")
```
## Usage
### 1. Initialize the Client
```swift
import EazyRestClient
let client = EazyRestClient(baseURL: "https://api.example.com/")
// Optional authorization
client.authToken = "Bearer "
```
### 2. Define a Request
```swift
struct MyRequest: EazyRestRequest {
typealias Response = MyResponseModel
var httpMethod: HTTPMethods { .get }
var resourceName: String { "endpoint" }
// Optionally override queryItems or bodyData
}
```
### 3. Callback-based Response Handling
```swift
client.send(MyRequest()) { result in
switch result {
case .success(let response):
print(response)
case .failure(let error):
print("Error: \(error.localizedDescription)")
}
}
```
### Or Async/Await Response Handling
```swift
// Requires iOS 15.0+, macOS 12.0+, tvOS 15.0+, watchOS 8.0+, visionOS 1.0+
Task {
do {
let response = try await client.send(MyRequest())
print(response)
} catch {
print("Error: \(error.localizedDescription)")
}
}
```
## Custom and Default Headers
By default, all requests include these HTTP headers:
```http
Accept: application/json
Content-Type: application/json
```
Override in a specific request if needed:
```swift
public extension MyCustomRequest: EazyRestRequest {
var headers: [String: String]? {
[
"Accept": "application/json",
"Authorization": "Bearer \(token)"
]
}
}
```
## Example App
An **ExampleApp** demonstrating both callback and async/await usage is located in the `Examples/` folder. Open `ExampleApp.xcodeproj` and run on your device or simulator.
## License
MIT License. © 2025 Pascale Beaulac