librelist archives

« back to archive

Routing inside packages?

Routing inside packages?

From:
Sumej
Date:
2015-04-28 @ 12:38
Hello, 
My code is: I have one main app.py that calls from subdirs classes. After 
that I create instances of them and adding route information. How can I 
add routing information in those api.role.role / api.services.service 
/ api.repository.key/ etc packages? 
As I see in  https://github.com/clione/sikre/blob/master/app.py there is 
same way. 
It's my app.py: import falcon from api.settings import rdepyconfig from 
api.settings.route import uri from api.role.role import RoleAPP, RolesAPP 
from api.services.service import ServiceAPP # pylint: disable=invalid-name

app = falcon.API() ROLEMNGR = RoleAPP(config_path=rdepyconfig.CONFIG_ROLE_FILE, 
                   config_path_all_roles=rdepyconfig.CONFIG_ROLES_FILE) 
ROLESMNGR = RolesAPP(config_path=rdepyconfig.CONFIG_ROLE_FILE,            
         config_path_all_roles=rdepyconfig.CONFIG_ROLES_FILE) 
app.add_route(uri('role'), ROLEMNGR) 
app.add_route(uri('roles/{action}'), ROLESMNGR) 
# services SERVICE_MNGR = ServiceAPP(rdepyconfig.CONFIG_SERVICES_FILE) 
app.add_route(uri('/service'), SERVICE_MNGR) 
app.add_route(uri('/service/{service_name}'), SERVICE_MNGR) 

Regards. 

Re: [falcon] Routing inside packages?

From:
Oscar Carballal
Date:
2015-04-28 @ 14:19
As far as I've seen, the is no way of decoupling the route statements from
the file that invokes the application itself.

You can try to build your own router and see if you can make it happen (
http://falcon.readthedocs.org/en/latest/api/routing.html) but even after
that the application instance (app) is the one that has to call the router.

Regards,
Oscar

--
Oscar Carballal Prego - Senior Software Developer
http://oscarcp.com | @pizte

On 28 April 2015 at 13:38, Sumej <valeranew@ukr.net> wrote:

> Hello,
>
> My code is:
> I have one main app.py that calls from subdirs classes. After that I
> create instances of them and adding route information.
>  How can I add routing information in those api.role.role
> / api.services.service / api.repository.key/ etc packages?
>  As I see in  *https://github.com/clione/sikre/blob/master/app.py
> <https://github.com/clione/sikre/blob/master/app.py> there is same way.*
>
>   *It's my app.py:*
>  *import falcon*
>  * from api.settings import rdepyconfig from api.settings.route import
> uri from api.role.role import RoleAPP, RolesAPP from api.services.service
> import ServiceAPP *
>  *# pylint: disable=invalid-name*
>   *app = falcon.API()*
>  *ROLEMNGR = RoleAPP(config_path=rdepyconfig.CONFIG_ROLE_FILE,*
>  *                   config_path_all_roles=rdepyconfig.CONFIG_ROLES_FILE)*
>  *ROLESMNGR = RolesAPP(config_path=rdepyconfig.CONFIG_ROLE_FILE,*
>  *
>  config_path_all_roles=rdepyconfig.CONFIG_ROLES_FILE)*
>  *app.add_route(uri('role'), ROLEMNGR)*
>   *app.add_route(uri('roles/{action}'), ROLESMNGR)*
>  # services
> SERVICE_MNGR = ServiceAPP(rdepyconfig.CONFIG_SERVICES_FILE)
>  app.add_route(uri('/service'), SERVICE_MNGR)
> app.add_route(uri('/service/{service_name}'), SERVICE_MNGR)
>
>
> Regards.
>