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.
- Host: GitHub
- URL: https://github.com/mezhevikin/http-request
- Owner: mezhevikin
- License: mit
- Created: 2022-08-31T08:39:17.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-12-30T11:13:36.000Z (about 3 years ago)
- Last Synced: 2025-06-07T21:16:32.626Z (8 months ago)
- Topics: alamofire, api, extension, foundation, http, http-client, ios, json, lightweight, macos, networking, nsurlsession, request, response, spm, swift, tiny, urlrequest, urlsession, wrapper
- Language: Swift
- Homepage:
- Size: 19.5 KB
- Stars: 30
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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)