Commit 17e5919a authored by Jacek Furmankiewicz's avatar Jacek Furmankiewicz

docs

parent e1b101be
...@@ -168,23 +168,23 @@ the body will be automatically parsed to JSON, YAML and XML (ElementTree) and at ...@@ -168,23 +168,23 @@ the body will be automatically parsed to JSON, YAML and XML (ElementTree) and at
* request.yaml * request.yaml
* request.xml * request.xml
@route("/post/json",(Http.POST,Http.PUT))
def test_json(self,request,**kwargs):
return "%s" % json.dumps(request.json)
@route("/post/xml",(Http.POST,Http.PUT)) @route("/post/json",(Http.POST,Http.PUT))
def test_xml(self,request,**kwargs): def test_json(self,request,**kwargs):
return "%s" % ElementTree.tostring(request.xml) return "%s" % json.dumps(request.json)
@route("/post/yaml",(Http.POST,Http.PUT)) @route("/post/xml",(Http.POST,Http.PUT))
def test_yaml(self,request,**kwargs): def test_xml(self,request,**kwargs):
return "%s" % yaml.dump(request.yaml) return "%s" % ElementTree.tostring(request.xml)
@route("/post/yaml",(Http.POST,Http.PUT))
def test_yaml(self,request,**kwargs):
return "%s" % yaml.dump(request.yaml)
*Routing requests by incoming content type* *Routing requests by incoming content type*
Based on the incoming content type in POST/PUT requests, Based on the incoming content type in POST/PUT requests, the *same* URL can be hooked up to different router methods:
the *same* URL can be hooked up to different router methods:
@route("/post/by/content",(Http.POST,Http.PUT),MediaType.APPLICATION_JSON) @route("/post/by/content",(Http.POST,Http.PUT),MediaType.APPLICATION_JSON)
def test_content_app_json(self,request,**kwargs): def test_content_app_json(self,request,**kwargs):
...@@ -205,8 +205,7 @@ the *same* URL can be hooked up to different router methods: ...@@ -205,8 +205,7 @@ the *same* URL can be hooked up to different router methods:
*Converting Python objects to content type based on what caller can accept* *Converting Python objects to content type based on what caller can accept*
Instead of returning string responses, the code can just return Python objects. Instead of returning string responses, the code can just return Python objects.
Depending whether the caller can accept JSON (default) or YAML, the Python objects Depending whether the caller can accept JSON (default) or YAML, the Python objects will be automatically converted:
will be automatically converted:
@route("/return/by/accept") @route("/return/by/accept")
def test_return_content_by_accepts(self,request,**kwargs): def test_return_content_by_accepts(self,request,**kwargs):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment