Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Adding HATEOAS support for data relation fields #1186

Closed
smeng9 opened this issue Sep 2, 2018 · 5 comments
Closed

Adding HATEOAS support for data relation fields #1186

smeng9 opened this issue Sep 2, 2018 · 5 comments
Milestone

Comments

@smeng9
Copy link
Contributor

smeng9 commented Sep 2, 2018

Hi,

I think it would be useful to add a reference sort of thing to the returned embedded field, if we want the user to navigate.


In https://eve-demo.herokuapp.com/ demo there are two domains -- works and people.
For now when we visit https://eve-demo.herokuapp.com/works, the embedded owner field in each of returned resource is just an objectid string with no href.

Expected Behavior

visit https://eve-demo.herokuapp.com/works

<resource href="works/5b89b1b091a5d0000495f56a" title="Work">
<_created>Fri, 31 Aug 2018 21:22:56 GMT</_created>
<_etag>9699888bc6e1d48fb52d3b573f302a24112802e8</_etag>
<_id>5b89b1b091a5d0000495f56a</_id>
<_updated>Fri, 31 Aug 2018 21:22:56 GMT</_updated>
<description>Description #25</description>
<owner href="people/5b89b1b091a5d0000495f54d">5b89b1b091a5d0000495f54d</owner>
<title>Book Title #25</title>
</resource>

visit https://eve-demo.herokuapp.com/works?embedded={%22owner%22:1}

<resource href="works/5b89b1b091a5d0000495f56a" title="Work">
<_created>Fri, 31 Aug 2018 21:22:56 GMT</_created>
<_etag>9699888bc6e1d48fb52d3b573f302a24112802e8</_etag>
<_id>5b89b1b091a5d0000495f56a</_id>
<_updated>Fri, 31 Aug 2018 21:22:56 GMT</_updated>
<description>Description #25</description>
<owner href="people/5b89b1b091a5d0000495f54d">
  <_created>Fri, 31 Aug 2018 21:22:56 GMT</_created>
  <_etag>103dab458e6e1cf1a70b74f770bb0cac9075a1c0</_etag>
  <_id>5b89b1b091a5d0000495f54d</_id>
  <_updated>Fri, 31 Aug 2018 21:22:56 GMT</_updated>
  <born>Wed, 25 Feb 1987 17:00:00 GMT</born>
  <firstname>Serena</firstname>
  <lastname>Love</lastname>
  <location>
  <address>363 Brannan St</address>
  <city>San Francisco</city>
  </location>
  <role>author</role>
</owner>
<title>Book Title #25</title>
</resource>

Actual Behavior

visit https://eve-demo.herokuapp.com/works

<resource href="works/5b89b1b091a5d0000495f56a" title="Work">
<_created>Fri, 31 Aug 2018 21:22:56 GMT</_created>
<_etag>9699888bc6e1d48fb52d3b573f302a24112802e8</_etag>
<_id>5b89b1b091a5d0000495f56a</_id>
<_updated>Fri, 31 Aug 2018 21:22:56 GMT</_updated>
<description>Description #25</description>
<owner>5b89b1b091a5d0000495f54d</owner>
<title>Book Title #25</title>
</resource>

visit https://eve-demo.herokuapp.com/works?embedded={%22owner%22:1}

<resource href="works/5b89b1b091a5d0000495f56a" title="Work">
<_created>Fri, 31 Aug 2018 21:22:56 GMT</_created>
<_etag>9699888bc6e1d48fb52d3b573f302a24112802e8</_etag>
<_id>5b89b1b091a5d0000495f56a</_id>
<_updated>Fri, 31 Aug 2018 21:22:56 GMT</_updated>
<description>Description #25</description>
<owner>
  <_created>Fri, 31 Aug 2018 21:22:56 GMT</_created>
  <_etag>103dab458e6e1cf1a70b74f770bb0cac9075a1c0</_etag>
  <_id>5b89b1b091a5d0000495f54d</_id>
  <_updated>Fri, 31 Aug 2018 21:22:56 GMT</_updated>
  <born>Wed, 25 Feb 1987 17:00:00 GMT</born>
  <firstname>Serena</firstname>
  <lastname>Love</lastname>
  <location>
  <address>363 Brannan St</address>
  <city>San Francisco</city>
  </location>
  <role>author</role>
</owner>
<title>Book Title #25</title>
</resource>

Environment

  • Python version: eve live demo
  • Eve version: eve live demo
@nicolaiarocci
Copy link
Member

I like it. Feel free to provide a PR if you feel like doing it.

@nicolaiarocci nicolaiarocci added this to the 0.8.2 milestone Oct 3, 2018
@smeng9 smeng9 changed the title Adding HATEOAS support for embedded fields Adding HATEOAS support for data relation fields Oct 12, 2018
@smeng9
Copy link
Contributor Author

smeng9 commented Oct 12, 2018

I changed the title from "embedded fields" to "data relation fields" because some of the embedded fields are embedded 'strongly-typed' dictionaries. Besides, all the data relation fields defined in the schema will apply to the hateoas support, not just the fields in the query url's embedded argument. Hope this will make it more clear.

@nicolaiarocci
Copy link
Member

Addressed by #1204

@s-eswar
Copy link

s-eswar commented Feb 13, 2019

@nicolaiarocci I have used the field as 'id' for the referenced collection instead of default '_id'. What should be the end-point query like:
I have tried http://127.0.0.1:5000/works?embedded={"owner":1} But this doesn't work. Can you check this https://stackoverflow.com/questions/54669278/fetch-data-of-the-reference-table-using-id-in-python-eve

@einarhuseby
Copy link
Contributor

einarhuseby commented Feb 13, 2019

@s-eswar your query is correct, however custom fields are not embeddable as of now. It will be fixed in 0.8.2, see #1225

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

4 participants