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

Split api routes declaration #191

Merged
merged 3 commits into from
Oct 5, 2015
Merged

Conversation

ael-code
Copy link
Member

@ael-code ael-code commented Oct 2, 2015

Cause it's not possible to use nested blueprint (pallets/flask#593) I've implemented a simple pattern to split api routes declaration. From now on every api groups will reside in it's own module.

This will make easier/cleaner to implement users api.

@ael-code ael-code added this to the 0.3 milestone Oct 2, 2015
@boyska
Copy link
Member

boyska commented Oct 2, 2015

I'll open an issue to reimplement all of Flask. Be quick, please. :P

thanks to the utilities introduced in `webant/util.py`
it is now passible to split routes declaration into multiple module

This commit moved archivant related api routes in its own module.

from flask import Blueprint, current_app, jsonify
from webant.util import add_routes
from archivant_api import routes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part is slightly counterintuitive: all this pull request is created so to make multiple modules adding routes to a single blueprint easier. But if you do from foo import routes you can only do it one time.
So probably

import archivant_api

add_routes(api, archivant_api.routes)

would be easier

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On 10/04/2015 01:26 PM, BoySka wrote:

In webant/api/blueprint_api.py
#191 (comment):

  •    self.err_code = err_code
    
  •    self.message = message
    

- self.details = details

  • def str(self):

- return "http_code: {}, err_code: {}, message: '{}', details: '{}'".format(self.http_code, self.err_code, self.message, self.details)

-def make_success_response(message, http_code=200):

  • response = jsonify({'code': http_code, 'message': message})
  • response.status_code = http_code

- return response

+from flask import Blueprint, current_app, jsonify
+from webant.util import add_routes
+from archivant_api import routes

this part is slightly counterintuitive: all this pull request is created
so to make multiple modules adding routes to a single blueprint easier.
But if you do |from foo import routes| you can only do it one time.
So probably

import archivant_api

add_routes(api, archivant_api.routes)

would be easier

There are at least two solution to the problem you've raised:

  • use the as keyword to differentiate the imported routes objects
    (used by me in users_api branch)
  • the one that you suggested, import all module and specify later.

I think this is a minor issue and we can change it at the next api
implementation. It's a simple import problem, but if you want to change
it now you need only to choose the solution you like most.

@ael-code
Copy link
Member Author

ael-code commented Oct 4, 2015

In the meanwhile I've rebased to solve conflicts with latest commits on master branch

boyska added a commit that referenced this pull request Oct 5, 2015
@boyska boyska merged commit e2623ed into insomnia-lab:master Oct 5, 2015
@ael-code ael-code deleted the nested_blueprint branch October 11, 2015 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants