resgateio / resgate

A Realtime API Gateway used with NATS to build REST, real time, and RPC APIs, where all your clients are synchronized seamlessly.
https://resgate.io
MIT License
685 stars 67 forks source link

Soft resource reference #157

Closed jirenius closed 4 years ago

jirenius commented 4 years ago

Issue

It should be possible to have "soft" resource references that Resgate won't automatically follow.

This would allow for breaking up large nested data structures into smaller parts, while keeping the references between them explicit.

Suggested solution

Extend RES Protocol - Resource reference with an optional "soft": true parameter, which marks the link as soft.

Example

{ "rid": "foo.model", "soft": true }

Resgate should not follow this link, but treat it as a simple value.

HTTP response

When the parent resource is fetched using HTTP, the reference should be presented as a href URL string:

Example HTTP response:

{
    "name": "Jane Doe",
    "profile": { "href": "/api/user/42/profile" } // Profile uses a soft link
}

ResClient (WS) response

The soft link should be turned into an object with a property, rid, returning the resource ID, and a method, get, which fetches the resource:

client.get('user.42').then(user => {
    console.log(user.name); // Jane Doe
    console.log(user.profile.rid); // user.42.profile
    user.profile.get() // Same as client.get('user.42.profile')
        .then(profile => (/* ... */));
});

Considerations

jirenius commented 4 years ago

Resolved in #160