JsonApiDotNetCore icon indicating copy to clipboard operation
JsonApiDotNetCore copied to clipboard

Are there plans to implement signalR hub / websockets for `{ json:api }` operations?

Open NullVoxPopuli opened this issue 6 years ago • 1 comments

With operations over sockets (or a SignalR Hub), it'd be possible to :

  • subscribe to certain URLs
    • with include, fields, etc, this would be the most similar to GraphQL's "Queries"
  • to asynchronously receive new data whenever the server decides you need it.
    • better two-way communication
    • have quicker reassurance with optimistic UIs, or quicker feedback if something goes wrong
    • quicker UI updates with pessimistic UIs
  • push any data down the socket at any time from any direction -- which may be a smidge faster, because the connection is already established.

NullVoxPopuli avatar Jan 24 '19 14:01 NullVoxPopuli

A rough implementation lives on over here: https://github.com/sillsdev/appbuilder-portal/pull/504

Some key points of interest:

  • SignalR "Hub" mounted at /hubs/data: https://github.com/sillsdev/appbuilder-portal/pull/504/files#diff-588e201e0899badfabf44b3dc2a863ffR196 (could be anywhere though afaik)
  • the Hub (thing that handles subscriptions / incoming data): https://github.com/sillsdev/appbuilder-portal/pull/504/files#diff-d6af4229367571a58deaf70c48c76fecR24
    • notes on subscribing to resources / individual record updates: https://github.com/sillsdev/appbuilder-portal/pull/504/files#diff-d6af4229367571a58deaf70c48c76fecR35
    • how handling incoming operations payloads happens: https://github.com/sillsdev/appbuilder-portal/pull/504/files#diff-d6af4229367571a58deaf70c48c76fecR53
  • some hacking I had to do, because I didn't know of a way to serialize { json:api } documents without a bunch of context: https://github.com/sillsdev/appbuilder-portal/pull/504/files#diff-343c7a12f38b97e20ca232021e1e039aR90
  • how a resource gets pushed to subscribers: https://github.com/sillsdev/appbuilder-portal/pull/504/files#diff-343c7a12f38b97e20ca232021e1e039aR135
  • on the react side, this is how subscribing to resources is initiated: https://github.com/sillsdev/appbuilder-portal/pull/504/files#diff-851df6a1a003c7095d96c8c29f6ec64fR28

NullVoxPopuli avatar Mar 07 '19 17:03 NullVoxPopuli