Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Resource identifier objects, override top level links. #64

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

RazerM
Copy link
Contributor

@RazerM RazerM commented Feb 18, 2017

Still needs documentation, do not merge.

This PR adds a resource_identifier keyword argument to Schema to dump resource identifier objects, as you would at a relationships endpoint, e.g. /users/<user_id>/relationships/articles.

In cases like this, both self and related URLs are different from the ArticleSchema we'd use to dump the data.

schema = ArticleSchema(
    many=True,
    resource_identifier=True,
    self_url='/users/1/relationships/articles',
    related_url='/users/1/articles',
)

The Flask extension uses views:

from flask import request

@app.route('/users/<int:user_id>/relationships/articles')
def user_articles_relationship(user_id):
    schema = ArticleSchema(
        many=True,
        resource_identifier=True,
        self_view=request.endpoint,
        self_view_kwargs=request.view_args,
        related_view='user_articles',
        related_view_kwargs={'user_id': user_id},
    )

The logic for this was put into get_top_level_links, like was done when the self_url and self_url_many options were added.

@RazerM
Copy link
Contributor Author

RazerM commented May 12, 2017

Would this be merged if I added documentation, or does this not fit your API?

@RazerM
Copy link
Contributor Author

RazerM commented Aug 22, 2018

bump?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant