HTTPClient
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 Repositry
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
View Github