GET & POST
-
Alamofire, Combine으로 POST 데이터 불러오기GET & POST 2022. 7. 15. 12:48
#1. ContentView import SwiftUI struct ContentView: View { @ObservedObject var randomUserViewModel = RandomUserViewModel() var body: some View { List(randomUserViewModel.randomUsers){ aRandomUser in RandomUserRowView(aRandomUser) } // List(0...100, id:\.self){ index in // RandomUserRowView() // } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }..
-
Post API 호출예GET & POST 2022. 7. 12. 16:25
import UIKit func makePostRequest(){ guard let url = URL(string: "https://jsonplaceholder.typicode.com/posts") else { return } print("Ready...") var request = URLRequest(url: url) //method, body, headers request.httpMethod = "POST" request.setValue("application/json", forHTTPHeaderField: "Content-Type") let body : [String: AnyHashable] = [ "userId" : 1, "title" : "test", "body" : "body1234" ] re..
-
SwiftUI GET & POST request, 예제 1GET & POST 2022. 6. 29. 17:46
import SwiftUI let getUrl = "https://jsonplaceholder.typicode.com/todos" let postUrl = "https://jsonplaceholder.typicode.com/posts" //Model struct Model: Decodable{ let userId: Int let id: Int let title: String let completed: Bool } struct PostModel: Decodable { let userId: Int let id: Int let title: String let body: String } //ViewModel class ViewModel: ObservableObject{ @Published var items = ..