Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

create base resource that consumes uri, falcon api instance, adds route and provides helper for constructing uris. #16

Closed
neetjn opened this issue Mar 18, 2018 · 1 comment

Comments

@neetjn
Copy link
Owner

neetjn commented Mar 18, 2018

No description provided.

@neetjn
Copy link
Owner Author

neetjn commented Mar 18, 2018

Proposed solution:

class BaseResource(object):

    route = ''

    @classmethod
    def url_to(cls, host, **kwargs) -> str:
        return f'{host}{cls.route.format(**kwargs)}'

...

class PostResource(BaseResource):

  route = '/v1/post/{post_id}'

  def on_get(self, req, res):
      pass


class PostCollectionResource(BaseResource):

  route = '/v1/posts/'

  def on_get(self, req, res):
      posts = get_posts()
      for post in posts:
          post.href = PostResource.url_to(req.netloc, post_id=post.id)

This isn't the cleanest method, and will disable resources from using route converters. This however will allow for much more streamline url construction for resource routes.

Repository owner deleted a comment from request-info bot Mar 18, 2018
@neetjn neetjn closed this as completed Mar 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant