how to insert data with Postgrest API
I have get data from postgresql with postgrest API in switUI,
here is my code for "SELECT * FROM USER;":
import Foundation
import Combine
class UserList: ObservableObject {
@Published var users: [User] = []
init() {
load()
}
func load() {
let url = URL(string: "http://localhost:3000/user")!
URLSession.shared.dataTask(with: url) { data, response, error in
DispatchQueue.main.async {
self.users = try! JSONDecoder().decode([User].self, from: data!)
}
}.resume()
}
}
//struct User: Decodable, Identifiable {
struct User: Decodable {
var id: Int
var name: String
}