json_api_client icon indicating copy to clipboard operation
json_api_client copied to clipboard

Initialize Resource without a request (from json api formatted streaming events)

Open blakecash opened this issue 8 years ago • 2 comments

I'm consuming a streaming api and events are coming over in text/event-stream format but the message in the event stream data key is in json api format. Is it possible to use this gem to initialize a resource from the json api formatted json?

Example event:

event: "event_name"
data: { "data":{ "id":"1", "type":"items", "links":{"self":"/api/v1/items/1"}, "attributes": { "foo":  "bar" } }

After the event message is parsed I'm left with the json api formatted json below.

{
  "data":{
  "id":"1",
  "type":"items",
  "links":{"self":"/api/v1/items/1"},
  "attributes": {
    "foo":  "bar"
  }
}

If I have an Item < JsonApiClient::Resource class is it possible to initialize it from the json above?

blakecash avatar Mar 07 '16 20:03 blakecash

Hi @blakecash , how is it going?

Did you finally achieve what you asked for? My team is trying to do something similar to use Redis with our client App to store the API call result.

Thanks in advice!

lmbautista avatar Feb 23 '17 09:02 lmbautista

+1

adis-io avatar Feb 26 '17 10:02 adis-io