An open API service indexing awesome lists of open source software.

https://github.com/mezhevikin/http-request

🌐 A tiny http client for iOS and macOS. Only 80 lines of code.
https://github.com/mezhevikin/http-request

alamofire api extension foundation http http-client ios json lightweight macos networking nsurlsession request response spm swift tiny urlrequest urlsession wrapper

Last synced: 7 months ago
JSON representation

🌐 A tiny http client for iOS and macOS. Only 80 lines of code.

Awesome Lists containing this project

README

          

# HttpRequest

A tiny http client for iOS and macOS. Only [80 lines](Sources/HttpRequest/HttpRequest.swift) of code.

### Get

```swift
let request = HttpRequest(
url: "https://httpbin.org/get",
parameters: ["name": "Alex"],
)
request.json(HttpBin.self) { json, response in
print(json)
}
```

### Post

```swift
let request = HttpRequest(
url: "https://httpbin.org/post",
method: .post,
parameters: ["name": "Alex"],
headers: ["User-Agent": "HttpRequest"]
)
request.json(HttpBin.self) { json, response in
if let json {
print(json)
} else if let error = response.error {
print(error)
}
}
```

### URLRequest and HTTPURLResponse

```swift
var request = HttpRequest(
url: "https://httpbin.org/get",
)
request.timeoutInterval = 30
request.cachePolicy = .reloadIgnoringCacheData
request.json(HttpBin.self) { json, response in
print(response.original.statusCode)
print(response.original.allHeaderFields)
}
```

### Json

```swift
struct HttpBin: Codable {
let args: [String: String]?
let form: [String: String]?
let headers: [String: String]?
}

HttpRequest(url: "https://httpbin.org/get").json(HttpBin.self) { json, response in
print(json)
}
```

### Data and String

```swift
HttpRequest(url: "https://httpbin.org/get").data() { data, response in
if let data {
let string = String(
data: data,
encoding: .utf8
)
print(string)
}
}

```

### Swift Package Manager

```
https://github.com/mezhevikin/http-request.git
```

### CocoaPods

```
pod 'HttpRequest', :git => 'https://github.com/mezhevikin/http-request.git'
```

### Links

🌐 [HttpRequest](https://github.com/mezhevikin/http-request-kotlin) for Kotlin/Android

💹 [Best Currency Converter](https://getconverter.org)

☕️ [Buy me a coffee](https://www.buymeacoffee.com/mezhevikin)