jeetrajput01/jnetworkmanager
Network manager wrapper for alamofire
Features
- Asynchronous Requests: Easily make asynchronous API calls with support for Codable types.
- File Uploads: Upload multipart form data, including files and parameters, with progress tracking.
- Error Handling: Comprehensive error handling for network-related issues, including timeouts and invalid URLs.
- Customizable Timeout: Set custom timeout intervals for requests.
Swift Package Manager
To integrate JNetworkManager into your project, you can use Swift Package Manager. Add the following line to your Package.swift file:
.package(url: "https://github.com/jeetrajput01/JNetworkManager.git", from: "1.3.4")cocoapods
To integrate JNetworkManager into your project, you can use cocoapods. Add the following line to your Podfile file:
pod 'JNetworkManager', '1.3.4'Usage
Making an Asynchronous Request
let result = await JNetworkManager.makeAsyncRequest(
url: "https://jsonplaceholder.typicode.com/posts",
method: .get,
parameter: nil,
type: [Post].self
)
switch result {
case .success(let data):
print("Data received: \(data)")
case .failure(let error):
print("Error occurred: \(error.localizedDescription)")
}Uploading Files
let mediaObject = mediaObject(data: fileData, filename: "file.txt", mimeType: "text/plain")
let result = await JNetworkManager.makeAsyncUploadRequest(url: "https://api.example.com/upload", method: .post, parameter: ["key": "value"], mediaObj: ["file": mediaObject])
switch result {
case .success(let response):
print("Upload successful: \(response)")
case .failure(let error):
print("Upload failed: \(error.localizedDescription)")
}Error Handling
The package provides a comprehensive error handling mechanism. It differentiates between various error types, including:
- No Internet Connection
- Authentication Errors
- Timeout Errors
- Invalid URLs
Alamofire
Link: Alamofire
Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
License
This project is licensed under the MIT License.
Package Metadata
Repository: jeetrajput01/jnetworkmanager
Default branch: main
README: README.md