Anthony and Massimo, I'd really thank you ppl for giving me a solution with 
some code! Thats wonderful!. 
It really helped me get going. Thanks again guys. :)  

Deepak

On Thursday, 16 August 2012 22:37:41 UTC+5:30, Anthony wrote:
>
> web2py does not use decorators to specify routes like Flask does (which 
> can get cumbersome and difficult to maintain with lots of routes). Instead, 
> first, you get default routing without making any explicit routing 
> specifications -- see the link I posted earlier: 
> http://web2py.com/books/default/chapter/29/4#Dispatching. In web2py, your 
> code translates to:
>
> In /myapp/controllers/default.py:
>
> def index():
>     return 'Welcome'
>
> def articles():
>     if request.args:
>         return 'Your are reading ' + request.args(0)
>     else:
>         return 'List of ' + URL()
>
> That will give you URLs like the following:
>
> /myapp
> /myapp/default/articles
> /myapp/default/articles/1
>
> Now, to get rid of "myapp" and "default", you can use one of the two 
> web2py URL rewrite 
> systems<http://web2py.com/books/default/chapter/29/4#URL-rewrite>. 
> In this case, the simplest is the parameter-based 
> system<http://web2py.com/books/default/chapter/29/4#Parameter-based-system>. 
> Just create a routes.py file in the /web2py folder with the following 
> content:
>
> routers = dict(
>     BASE = dict(
>         default_application = 'myapp'
>     )
> )
>
> Specifying the default application, controller, and function removes them 
> from the URLs. The default controller and default function are already set 
> to "default" and "index", respectively, so you don't have to specify those 
> explicitly in the router (you would have to specify them if you used 
> different names). So, by creating the routes.py file and adding "myapp" as 
> the default application, we now get the routes you want:
>
> /
> /articles
> /articles/1
>
> Of course, if it's just an API, you don't necessarily need to remove the 
> application and controller name from the URLs. You might instead consider 
> creating a separate api.py controller file with the above index() and 
> articles() functions in it. Then, even without any routes.py file, you 
> would get URLs like:
>
> /myapp/api
> /myapp/api/articles
> /myapp/api/articles/1
>
> This is all with web2py's default routing -- no need to specify any routes 
> at all (web2py will automatically look for the index() function when you 
> request a URL with only a controller, like /myapp/api).
>
> You might also want to look at 
> http://web2py.com/books/default/chapter/29/10#Restful-Web-Services.
>
> Anthony
>
> On Thursday, August 16, 2012 5:05:21 AM UTC-4, deepak wrote:
>>
>> I would like to perform REST Services by mapping url to the 
>> controller-function. For eg:
>>
>> @app.route('/')def api_root():
>>     return 'Welcome'
>> @app.route('/articles')def api_articles():
>>     return 'List of ' + url_for('api_articles')
>> @app.route('/articles/<articleid>')def api_article(articleid):
>>     return 'You are reading ' + articleid
>>
>> which could be done in Flask. Basically i would want to match the URLs to 
>> the service in web2py.
>>
>> On Tuesday, 14 August 2012 23:43:20 UTC+5:30, Anthony wrote:
>>>
>>> It looks like you could do all of that with web2py. Can you be more 
>>> specific regarding how you want your URLs to look and what they should 
>>> retrieve. In addition to RESTful services and routing, have you looked at 
>>> the basics: http://web2py.com/books/default/chapter/29/4#Dispatching?
>>>
>>> Anthony
>>>
>>> On Tuesday, August 14, 2012 1:10:58 PM UTC-4, deepak wrote:
>>>>
>>>> I want to use RESTful URL patters likewise in Flask, '
>>>> http://publish.luisrei.com/articles/flaskrest.html'
>>>>>
>>>>> All I could end up finding was to make use of routes.py [routes_in & 
>>>> routes_out]. 
>>>>
>>>> Deepak
>>>>
>>>

-- 



Reply via email to