<BlockSwitcher>

<Block name="Async/Await">

```swift
func postTodo() async {
    let message = #"{"message": "my new Todo"}"#
    let request = RESTRequest(path: "/todo", body: message.data(using: .utf8))
    do {
        let data = try await Amplify.API.post(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)")
    }
}
```

</Block>

<Block name="Combine">

```swift
func postTodo() -> AnyCancellable {
    let message = #"{"message": "my new Todo"}"#
    let request = RESTRequest(path: "/todo", body: message.data(using: .utf8))
    let sink = Amplify.Publisher.create {
        try await Amplify.API.post(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
}
```

</Block>

</BlockSwitcher>
