Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8518395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:57:59+00:00 2026-06-11T05:57:59+00:00

I’ve read around and found this answered question about a problem relating to this

  • 0

I’ve read around and found this answered question about a problem relating to this but what I really want to know is how to implement this structure and how many handler classes I need:

1  GET    /items        #=> index
2  GET    /items/1      #=> show
3  GET    /items/new    #=> new
4  GET    /items/1/edit #=> edit
5  PUT    /items/1      #=> update
6  POST   /items        #=> create
7  DELETE /items/1      #=> destroy

I was thinking having 2,5,7 mapped to a single handler routed to /items/[0-9]+ and having 3 new handlers for the items, items/new and /items/[0-9]+/edit. The downside is that it felt like a sub-optimal solution to have 4 handlers for a single resource.

I’m terribly new to proper routing/handling/webapps but I at least give it a good read before I start on something. Are there any better suggestions for how many/how you route your handlers?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:58:00+00:00Added an answer on June 11, 2026 at 5:58 am

    Well, it is largely stylistic. Each request handler in this situation
    represents the removal of an if statement from one of your methods. I think it
    can be clearer to limit the number of RequestHandlers. The clearest
    results I think can be achieved with one handler and three routes.

    I’ve also thrown away your item 3. Because it is a duplication of item 6. If
    having an ‘items/new’ url is really important then we could put it back in.
    Though I think at that point you would need another handler class for clarity.

    class ItemHandler(tornado.web.RequestHandler):
    
        def get(self, item_id=None, edit=False):
            if item_id:
                # get item from db
                if edit:
                    new_data_from_query_string = self.get_argument('item_data')
                    # do edit, save item
                # return item
            else:
                # return index
    
        def put(self, item_id):
            data = self.get_argument('item_data')
            # do your update for item
    
        def post(self):
            data = self.get_argument('item_data')
            # do your item creation
    
        def delete(self, item_id):
            # do your deletion for item_id
    

    Then the actual application could be created like this:

    tornado.web.application([
        (r'/items$', ItemHandler),
        (r'/items/(\d+$)', ItemHandler),
        (r'/items/(\d+)/(edit)$', ItemHandler),
    ])
    

    If you want the ‘/items/new’ url then I would probably suggest putting that in
    a separate handler because it would otherwise make the logic overly complex.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This could be a duplicate question, but I have no idea what search terms
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I don't have much knowledge about the IPv6 protocol, so sorry if the question
Does anyone know how can I replace this 2 symbol below from the string
I want to construct a data frame in an Rcpp function, but when I
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.