- Client registers subscription
PUT /baseDstu2/Subscription HTTP/1.1
(subscription resource in body)
- Client Connects to server and upgrades to Websocket
GET /websocket/dstu2 HTTP/1.1
Host: fhirtest.uhn.ca
Upgrade: websocket
Connection: Upgrade
- Client sends bind request (123 is the ID of the subscription)
bind 123
- Server responds with a bind
bound 123
- When new resources are available, server sends a ping to the client via websocket. Ping contains the ID of the subscription
ping 123
- Client performs an updated search
http://fhirtest.uhn.ca/baseDstu2/Observation?patient=Patient/1425
- Client Connects to server and upgrades to Websocket
GET /websocket/dstu2 HTTP/1.1
Host: fhirtest.uhn.ca
Upgrade: websocket
Connection: Upgrade
- Client sends bind request containing a search to perform
- Note on format, the client may optionally specify an encoding using the
_format
parameter. If no encoding is specified, the server may choose an appropriate default.
- Note on format, the client may optionally specify an encoding using the
bind http://fhirtest.uhn.ca/baseDstu2/Observation?patient=Patient/1425&_format=json
- Server creates a new subscription and responds with a bind (123 is the ID of the newly created subscription)
bound 123
- Alternately, if the server rejects the search criteria or otherwise refuses to create the subscription, the server may respond with an error response containing an HTTP status code and text
error 400 Invalid search criteria
- When a new resource has been created which matches the search criteria (or an existing one has been updated), the server sends a message to the client via websocket. The message contains the phrase
add [subscription Id]
, followed by one newline (\n), followed by the resource body. If multiple resources have been updated, one message is sent for each resource.
add 123
{
"resourceType":"Patient"
}
-
When the client closes the Websocket, the server may opt to delete the subscription "the server may opt to delete the subscription. what happens if it doesn't?" - I'd suggest this is an implementation detail. If the client hangs up, it might be because the user refreshed their browser so it might be nice to let them resume the existing subscription, but a server might also just choose to not allow that.
-
The client may also opt to manually close the connection by sending a cancel request to the server
cancel