2
내 목표는 CherryPy (wsgi) + uWSGI + Nginx를 사용하여 RESTful API를 정의하는 것입니다. #python에 나와 같이 OPTIONS 메서드를 처리하는 방법을 궁금하네요. 이 메서드에 대한 처리기를 구현하면 호출자가 내 API에 어떤 메서드가 지원되는지, 어떤 메서드가 지원되지 않는지 이해하는 데 도움이됩니다.CherryPy에서 http 옵션 메서드를 정의하는 방법은 무엇입니까?
는 여기에 지금까지있어 무엇 :
#!/usr/bin/env python
import cherrypy
# modules used for data access
import nosql
import dao
class Product(object):
exposed = True
def GET(self, key, *args, **kwargs):
try:
p = Product(nosql.get(key))
return p.json
except:
# return 500 error with traceback if debug
pass
def POST(self, *args, **kwargs):
try:
p = dao.Product(*args, **kwargs)
k = nosql.generate_key(Product.__name__)
nosql.set(k,str(p))
except:
# return 500 error with traceback if debug
pass
def OPTIONS(self, *args, **kwargs):
"""
The question is, what to return here? I'm looking
at the following rfc:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
"""
return "GET, POST"
conf = {
'/': {
'request.dispatch':cherrypy.dispatch.MethodDispatcher(),
},
}
application = cherrypy.tree.mount(Product, config=conf)