Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated Apr 29, 2024

Update data

Update data

Put data to the API endpoint:

func putTodo() async {
let updatedMessage = #"{"message": "my updated Todo"}"#
let request = RESTRequest(path: "/todo", body: updatedMessage.data(using: .utf8))
do {
let data = try await Amplify.API.put(request: request)
let str = String(decoding: data, as: UTF8.self)
print("Success: \(str)")
} catch let error as APIError {
print("Failed due to API error: ", error)
} catch {
print("Unexpected error: \(error)")
}
}
func putTodo() -> AnyCancellable {
let updatedMessage = #"{"message": "my updated Todo"}"#
let request = RESTRequest(path: "/todo", body: updatedMessage.data(using: .utf8))
let sink = Amplify.Publisher.create {
try await Amplify.API.put(request: request)
}
.sink {
if case let .failure(apiError) = $0 {
print("Failed", apiError)
}
}
receiveValue: { data in
let str = String(decoding: data, as: UTF8.self)
print("Success \(str)")
}
return sink
}