Kyle Fransham
Kyle Fransham

Reputation: 1879

cherrypy dynamically add objects

I'm using cherrypy to mimic an existing RESTful interface. One requirement is that I have is to be able to add objects on the fly.

So, for example, let's say I have an object, called myobj. I want to be able to expose a method that is based on an object added by the user. So, I would have an "add" context, where I create the object

http://example.ex/myobj+create

and I would be able to retrieve the object that's created, as well as any children:

http://example.ex/myobjs/obj1
http://example.ex/myobjs/obj1/child1

Is this possible with cherrypy? Should I be investigating a different framework?

Upvotes: 2

Views: 368

Answers (3)

fumanchu
fumanchu

Reputation: 14559

Yes, you can add handlers dynamically. Just execute obj1.child1 = Child(...).

Upvotes: 0

Sylvain Hellegouarch
Sylvain Hellegouarch

Reputation: 851

You probably want to look at the _cp_dispatch or popargs facilities that CherryPy 3.2+ offers. They are less known and unfortunately I couldn't find proper doc for them but they would do what you're after. Alternatively, you could use the Routes or selector dispatchers.

Upvotes: 1

Nicola Coretti
Nicola Coretti

Reputation: 2685

CherryPy 3.2 (REST) provides an interface for creating RESTful interfaces.

Upvotes: 0

Related Questions