Using If-modified-since on relationships


#1

Hello there,

I want to load a resource called, store, and store has relationship “loyalty plan”, and another relationship “locations”.

Each relationship has it’s endpoint as well.

However, client loves to load the store information with all it’s relationships at once. I’d like to have a way for client to tell server,

’ if relation last modified since “yyyy-mm-dd hh:mm” then return the resource, if not, return 304 code in the relationship’

How does it sounds for you? does this makes sense?

{
  "data": {
    "type": "store",
    "id": "32627",
    "attributes": {
      "name": "Pet Shop Store"
    },
    "relationships": {
      "loyalty": {
        "data": [
          {
            "type": "loyalty_level",
            "id": "1",
            "attributes": {
              "needed": 0,
              "every": 1,
              "statusEarn": 1,
              "walletEarn": 1,
              "description": "Every 1$ spent, earn 1 points"
            }
          }
        ]
      },
      "locations": {
        "errors": {
          "status": "304",
          "detail": "No changes on this resource"
        }
      }
    }
  }
}

P.S - Initially I thought to have there “null” but what if store was modified and doesn’t have any locations at the moment?


#2

HTTP/2 is tailor-made for this use case. Instead of side-unloading related resources, tell your client(s) to make separate requests—which will be multiplexed over HTTP/2—and your server can handle If-Modified-Since differently for each endpoint. Introducing such functionality into the {json:api} spec would be reinventing the wheel.