JNetworkManager

1.3.3

Network manager wrapper for alamofire
jeetrajput01/JNetworkManager

What's New

Sendable issue

2025-04-03T06:45:13Z

bug fixes

JNetworkManager

Network manager wrapper for alamofire

JNetworkManager is a Swift package that simplifies making asynchronous network requests using Alamofire. It provides a set of utility functions to handle standard and multipart requests with ease, while managing error handling and response parsing seamlessly.

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.

Installation

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.3")

cocoapods

To integrate JNetworkManager into your project, you can use cocoapods. Add the following line to your Podfile file:

pod 'JNetworkManager', '1.3.1'

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

AnyCodable

Link: AnyCodable

Contributing

Contributions are welcome! Please feel free to submit issues and pull requests.

License

This project is licensed under the MIT License.

Description

  • Swift Tools 6.0.0
View More Packages from this Author

Dependencies

Last updated: Thu May 15 2025 04:49:25 GMT-0900 (Hawaii-Aleutian Daylight Time)