I'm getting started with Pyramid, and am excited about traversal as a routing strategy. It seems natural and powerful. However, my thinking has led me down a questionable path. Can you suggest a better pattern?
I'm trying to implement a few RESTful routes. For example, I'd like to map the following:
- GET /users -> index
- GET /users/chris -> show
- GET /users/new -> new
- POST /users -> create
- PUT /users/chris -> update
- DELETE /users/chris -> destroy
It seems like the final context of the show and update actions ought to be the appropriate instance of User, but what about index and create? It seems like the User class itself would be an appropriate context, however the traversal mechanism, the __getitem__ method, can't be implemented on classes without some metaclass magic. It seemed like there might be a cleaner way to do this. Obviously I could create a UserResourceContainer whose only job would be to handle traversal, but I'm attracted to the elegance of using the User class. Thoughts?