-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Problem
It would be really useful for PostgREST to generate links to embedded resources. That would make it easier to implement UIs allowing navigation between related resources.
Right now clients have to embed the knowledge of unique/primary/foreign keys which is duplication of metadata already known to PostgREST.
Solution
Provide _self
syntax, eg:
http://localhost:3000/films?select=title,director:directors(last_name,_self)
- provide last_name
and URI to full representation (eg. http://localhost:3000/directors?id=eq.2
)
http://localhost:3000/films?select=title,_self
- provide title and URI to full representation (eg. http://localhost:3000/films?id=eq.432
)
http://localhost:3000/films?select=title,director:directors(last_name,_self(films))
- provide last_name
and URI to retrieve director's films (eg. http://localhost:3000/directors?id=eq.2&select=films
)
The problem has been earlier discussed in several issues: https://github.com/PostgREST/postgrest/issues?q=hateoas - but it seems like no solution has been found. Not really sure if _self
link syntax is the right solution: if it is general enough and/or compliant to some standard, but I think it might be good enough for many scenarios. The nice thing about it is that it is opt-in.