post content-type "application/x-www-form-urlencoded", and json message response format

20 views
Skip to first unread message

AAG

unread,
Aug 26, 2011, 9:02:18 AM8/26/11
to ProtoRPC Discuss

In the context of a client post with content-type "application/x-www-
form-urlencoded", Is it possible to use ProtoRPC (python) to generate
a json message response format.

How can i apply this feature in the following sample:

from google.appengine.ext import webapp
from google.appengine.ext.webapp import util

from protorpc import messages
from protorpc import remote
from protorpc.webapp import service_handlers

class HelloRequest(messages.Message):
my_name = messages.StringField(1, required=True)

class HelloResponse(messages.Message):
hello = messages.StringField(1, required=True)

class HelloService(remote.Service):

@remote.method(HelloRequest, HelloResponse)
def hello(self, request):
return HelloResponse(hello='Hello there, %s!' % request.my_name)

service_mappings = service_handlers.service_mapping(
[('/hello', HelloService),
])

application = webapp.WSGIApplication(service_mappings)

def main():
util.run_wsgi_app(application)

if __name__ == '__main__':
main()

Rafe Kaplan

unread,
Aug 26, 2011, 3:41:50 PM8/26/11
to google-prot...@googlegroups.com
It is difficult to get ProtoRPC to do this as implemented. There is
planned support in the future for ProtoRPC to use the Accept header in
order to permit responses with different content types than the
request. I am guessing you want this to make it easier to write Ajax
based clients?

If you are going to enable application/x-www-form-urlencoded for
your service, please note that it is disabled by default and may open
your service up to some security risks. It used to be enabled by
default but no longer is. It is still possible to use but requires
some additional set up.

Reply all
Reply to author
Forward
0 new messages