## Pear-HTTPFetcher-iOS
Pear-HTTPFetcher-iOS is a convenient, lightweight HTTP client library for iOS. This library allows you to effortlessly make HTTP requests and handle responses in your iOS applications.
## Key Features
– **Simplified API**: Pear-HTTPFetcher-iOS provides a straightforward API for performing HTTP requests, making it easy to integrate into your iOS projects.
– **Supports Multiple Request Types**: With Pear-HTTPFetcher-iOS, you can send GET, POST, PUT, DELETE, and other HTTP requests effortlessly.
– **Asynchronous Requests**: Perform HTTP requests asynchronously, ensuring your application remains responsive during network operations.
– **Customizable Headers**: Easily add custom headers to your requests, allowing for authorization, user-agent identification, and more.
– **Request and Response Interception**: Pear-HTTPFetcher-iOS offers request and response interception points, enabling you to modify and analyze requests and responses.
– **Support for Authentication**: Authenticate your requests with various authentication methods such as Basic, Digest, OAuth, and more.
– **Progress Tracking**: Track the progress of your HTTP requests, whether it is uploading or downloading data.
– **SSL/TLS Support**: Pear-HTTPFetcher-iOS supports secure connections using SSL/TLS protocols, ensuring data integrity and confidentiality.
– **Timeout Configuration**: Set the timeout duration for requests, ensuring your app doesn’t hang indefinitely while waiting for a response.
## Installation
“`shell
pod ‘Pear-HTTPFetcher-iOS’
“`
To install Pear-HTTPFetcher-iOS via [CocoaPods](https://cocoapods.org), simply add the above line to your Podfile and run `pod install`.
## Usage
To use Pear-HTTPFetcher-iOS in your iOS project, follow these steps:
1. Import the library into your Swift project:\
“`swift
import PearHTTPFetcher
“`
2. Create an instance of `PearHTTPFetcher`:\
“`swift
let fetcher = PearHTTPFetcher()
“`
3. Make an HTTP Request:\
“`swift
fetcher.get(“https://api.example.com/endpoint”) { (result) in
switch result {
case .success(let response):
// Do something with the response
print(response)
case .failure(let error):
// Handle the error
print(error)
}
}
“`
## API Reference
### `PearHTTPFetcher`
The `PearHTTPFetcher` class allows you to make HTTP requests and handle responses.
#### Methods
“`swift
func get(_ url: String, completion: @escaping (Result
“`
Performs a GET request to the specified `url`.
“`swift
func post(_ url: String, parameters: [String: Any]?, headers: [String: String]?, completion: @escaping (Result
“`
Sends a POST request to the specified `url` with optional `parameters` and custom `headers`.
#### Examples
“`swift
fetcher.get(“https://api.example.com/data”) { (result) in
switch result {
case .success(let response):
// Handle successful response
print(response)
case .failure(let error):
// Handle error
print(error)
}
}
“`
“`swift
let parameters = [“username”: “john”, “password”: “secretpass”]
let headers = [“Authorization”: “Bearer TOKEN123”]
fetcher.post(“https://api.example.com/login”, parameters: parameters, headers: headers) { (result) in
switch result {
case .success(let response):
// Handle successful response
print(response)
case .failure(let error):
// Handle error
print(error)
}
}
“`
## Conclusion
Pear-HTTPFetcher-iOS simplifies the process of making HTTP requests in your iOS applications. With its easy-to-use API and various features, you can effortlessly communicate with web services and handle responses effectively.