[Twisted-web] Leaf Resources with child Leaf Resources

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Wed Feb 29 16:12:43 EST 2012


On 09:00 pm, jacek99 at gmail.com wrote:
>OK, so the issue I have is that I cannot create two separate REST 
>Resources
>with nested URLs  e.g.
>
>class CustomerRestService(Resource):
>     """Handles REST operations for Customer /customer"""
>
>class CustomerAddressRestService(Resource):
>     """Handles REST operations for Customer Address
>/customer/<customerId>/address"""
>     pass
>
>Instead I would need to have one common Resource that handles 
>everything
>under '/customer',
>including the customer entity and customer address entity in one (and 
>any
>other entity whose root is '/customer').

I don't understand what this means.  It sounds like you're saying you 
have to have CustomerRestService be a leaf resource.  You don't have to. 
If you don't want it to be a leaf resource, don't make it a leaf 
resource.  The way you not making it a leaf resource is by not setting 
`isLeaf = True` on it.
>That isn't a very good design...especially if you maybe have 50 
>different
>entities hooked up  under '/customer' (like in our app).
>It seems in order to enable having nice cohesive classes that provide a
>REST service for just one entity I would need to manually
>route the request from the root Resource into each of them myself.
>
>That is what i was trying to avoid, but it looks like there is no other
>choice.

I still don't understand the problem you're having.  As I said, 
regarding the "solution" I gave in my previous email, it's just how you 
would achieve the behavior I thought maybe you were trying to describe 
wanting, but I don't really understand what you're trying to accomplish 
or why.

Jean-Paul



More information about the Twisted-web mailing list