Skip to content

HATEOAS Resource Embeddings (_self link) #4236

@mkleczek

Description

@mkleczek

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions