Swiftpack.co - zunda-pixel/HTTPClient as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by zunda-pixel.
zunda-pixel/HTTPClient 1.1.0
HTTPClient for Swift
⭐️ 0
🕓 7 weeks ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/zunda-pixel/HTTPClient.git", from: "1.1.0")

HTTPClient

Support Swift 5.5

Support Platform for iOS macOS watchOS tvOS Linux Windows

Ex. Search Repository

import HTTPClient

let url: URL = .init(string: "https://api.github.com/search/repositories")!

let queries = [
  "q": "zunda_pixel"
]

let (data, htttpResponse) = try await HTTPClient.get(url: url, queries: queries)

print(String(data: data, encoding: .utf8)!)

Ex. Create Repository

import HTTPClient

let url:URL = .init(string: "https://api.github.com/user/repos")!

let headers = [
  "Authorization": "Bearer AAAAAAAAAAAAdfklsajflksjadflkasdjflk",
]

let body = [
  "name": "blog"
]

let bodyData = try JSONEncoder().encode(body)

let (data, urlResponse) = try await HTTPClient.post(url: url, headers: headers, body: bodyData)

print(String(data: data, encoding: .utf8)!)

Ex. Delete Repository

import HTTPClient

let userID = "zunda_pixel"
let repositoryName = "HTTPClient"
let url:URL = .init(string: "https://api.github.com/repos/\(userID)/\(repositoryName)")!

let headers = [
  "Authorization": "Bearer AAAAAAAAAAAAdfklsajflksjadflkasdjflk",
]

let (data, urlResponse) = try await HTTPClient.delete(url: url, headers: headers)

print(String(data: data, encoding: .utf8)!)

Ex. Update Repository

import HTTPClient

let userID = "zunda_pixel"
let repositoryName = "HTTPClient"
let url:URL = .init(string: "https://api.github.com/repos/\(userID)/\(repositoryName)")!

let headers = [
  "Authorization": "Bearer AAAAAAAAAAAAdfklsajflksjadflkasdjflk",
]

let body = [
  "name": "newName"
]

let bodyData = try JSONEncoder().encode(body)
let (data, urlResponse) = try await HTTPClient.patch(url: url, headers: headers, body: bodyData)

print(String(data: data, encoding: .utf8)!)

GitHub

link
Stars: 0
Last commit: 3 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Fix delete method
14 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics