Imagine we have chat service with websocket. We are sending message as JSON with property request_id
. Server catches our message, saves it to the DB and returns message's id
by sending another data back to the client with passed request_id
. Client has to find out what exactly "request" is this "response" related to and save data to the local DB.
For example:
- Client sends message:
{
"request_id": "1st",
"content": "first message"
}
- Server receives message, saves it and returns new message's id
{
"request_id": "1st",
"message_id": 123242139857814
}
Starscream lib doesn't provide such mechanic, unlike Alammofire (that uses closures). I am looking for a solution that will be compatible with CoreData and RxSwift. How can I handle server's "response" without loosing "request" context?
There are lots of ways. As an example, you can use the next code