8

How to read parameters from GET request in CherryPy ? I generate request from JQuery like

$.get(
    "http://localhost:8080/temp",
    "{a:10}",
    function(data) { alert(data); },
    "html"
);

and I have class temp with @cherrypy.expose function index(self). How to extract data from GET request ?

Jana
  • 529
  • 2
  • 7
  • 8

3 Answers3

13
@cherrypy.expose
def index(self, param)

where param is your GET param

Alan W. Smith
  • 24,647
  • 4
  • 70
  • 96
virhilo
  • 6,568
  • 2
  • 29
  • 26
11

As virhilo mentioned, you can take named parameters in with your method.

Also, you can read cherrypy.request.params.

Ken Kinder
  • 12,654
  • 6
  • 50
  • 70
8

With both POST and GET (and PUT, PATCH, etc...) you can use:

cherrypy.request.params.get(key_name)

Where key_name is the key name you want to get.

ocodo
  • 29,401
  • 18
  • 105
  • 117