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.
ð APIManager Using Alamofire
A reusable Swift API Manager built using Alamofire, designed to handle all HTTP requests (GET, POST, PUT, DELETE, and Multipart) efficiently. This module provides a clean, modular, and scalable networking layer for iOS apps â supporting custom headers, request encodings, loader visibility, and unified error handling.
ð§Đ Features
â Universal support for GET, POST, PUT, DELETE, and Multipart requests
âïļ Configurable Parameter Encoding (JSONEncoding, URLEncoding, MultipartFormData)
ð§ą Built-in Loader Control for managing UI state during API calls
ð Easily attach Authorization Headers (e.g., JWT, Bearer tokens)
ðŠķ Lightweight and reusable â integrates seamlessly with any MVVM or MVC architecture
ðĄ Custom response handler supporting both Codable parsing and raw dictionary response
ð§° Tech Stack
Language: Swift 5+
Framework: Alamofire 5+
Architecture: Clean Networking Layer
Platform: iOS 14.0+
ðĶ Installation
Add Alamofire using Swift Package Manager (SPM):
In Xcode, go to File â Add Packages...
Enter the repository URL:
https://github.com/Alamofire/Alamofire.git
Choose the latest version and add it to your project target.
Then clone or copy the API_Manager files into your project.
ð§ 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.