Friday, 15 March 2013

python - Minimalist cherrypy website with PUT method -



python - Minimalist cherrypy website with PUT method -

i trying create minimalist website accepts 2 requests. first request on '/', should reply simple string. sec set request on '/put_url' accepts chuck of data. here have far:

import cherrypy class main(object): @cherrypy.expose def index(self): homecoming "hy?" class uploader(object): exposed = true def put(self, data): print "hello" print info if __name__ == '__main__': conf = { '/put_url': { 'request.dispatch': cherrypy.dispatch.methoddispatcher(), 'tools.response_headers.on': true, 'tools.response_headers.headers': [('content-type', 'text/plain')] } } webapp = main() webapp.put_url = uploader() cherrypy.quickstart(webapp, '/', conf)

how thing work? reason can't figure out. thanks.

add take header. add together decorator set method.

class uploader(object): exposed = true @cherrypy.tools.accept(media='text/plain') def put(self, data): print "hello" print info

you may not want utilize text/plain take header. depends on application.

to test can use

curl -x set -d data=xyz localhost:8080/put_url

python rest cherrypy put

No comments:

Post a Comment