rahulsohaliya120/rsapimanager
A reusable Swift API Manager using Alamofire. Supports GET, POST, PUT, DELETE, and Multipart requests with flexible encodings, headers, and error handling — perfect for any iOS project.
📦 Installation (Swift Package Manager)
To integrate RSAPIManager into your Xcode project:
Option 1 — Using Xcode UI
- Open your project in Xcode.
- Go to File → Add Packages...
- Enter the repository URL: https://github.com/rahulsohaliya120/RSAPIManager.git
- Choose Version: Up to Next Major (1.2.0 < 2.0.0)
- Add the package to your project target.
Option 2 — Using Package.swift
If you’re using your own Swift Package, add this dependency:
dependencies: [
.package(url: "https://github.com/rahulsohaliya120/RSAPIManager.git", from: "1.2.0")
]Then import it:
import RSAPIManagerOption 3 — CocoaPods
To integrate RSAPIManager using CocoaPods, add this line to your Podfile:
pod 'RSAPIManager', '~> 1.2.0'Then run:
pod installNow import it:
import RSAPIManager🧠 Usage Example
1️⃣ Basic GET Request (with Codable)
API_Manager.shared.GET_METHOD(
requestURL: "objects",
encodingType: .urlEncoding,
isShowLoader: true,
responseType: [Object].self
) { responseType, error, responseDict, model in
switch responseType {
case .SUCCESS:
print("✅ Data:", model ?? [])
case .ERROR:
print("❌ Error:", error?.localizedDescription ?? "Unknown error")
}
}
2️⃣ Raw Dictionary Response (without model)
API_Manager.shared.GET_METHOD(
requestURL: "objects",
encodingType: .urlEncoding,
isShowLoader: true
) { responseType, error, responseDict in
switch responseType {
case .SUCCESS:
print("✅ Response Dict:", responseDict ?? [:])
case .ERROR:
print("❌ Error:", error?.localizedDescription ?? "Unknown error")
}
}🧩 Example Parameter Encodings
| Encoding Type | Description | Use Case | | --------------- | -------------------------------------- | --------------------------- | | .jsonEncoding | Sends data as JSON in the request body | POST, PUT APIs | | .urlEncoding | Sends data in the URL query string | GET, lightweight requests | | .multipart | Sends files and form data together | File/Image uploads |
⚡ Error Handling
All error codes (400, 401, 403, 404, 500, etc.) are standardized under a single HTTPError enum for easy debugging and consistent logging.
🧑💻 Author
Rahul Sohaliya 📧 GitHub Profile
🪪 License
This project is licensed under the Apache License 2.0 — see the LICENSE file for details.
Package Metadata
Repository: rahulsohaliya120/rsapimanager
Default branch: main
README: README.md