Is ProtoRPC API the GAE built-in for ajax?

385 Views Asked by At

Next step: an ajax frontend for a gae/py app.

My app have only basic html version that interacts with the datastore and updates the page everytime. It's ok but now it needs ajax. I tried some solution: basic javascript, jquery's ajax API and some frameworks.

I think I found everything I was looking for in knockoutjs but this framework interacts with the server throught the json format. This means that i need learn the json library and rewrite all handlers so get and post in json. I can start this task but before I want understood something more about ProtoRPC API.

The docs says that this API is useful also for "Creating structured Ajax backends" and if I understood fine the messages in response is in json format. My questions is:

It's true that ProtoRPC API messages use json?

It will be a problem that all the request/response pass throught ProtoRPC?

Implement a server-side solid ProtoRPC service and use the framework for client-side is a good strategy?

2

There are 2 best solutions below

1
On BEST ANSWER

ProtoRPC comes with a JSON implementation of its transmission protocol.

You should be able to build your server side logic using ProtoRPC, and issue HTTP request to your API endpoints with messages encoded in JSON, as described on the ProtoRPC overview in the official documentation.

Knockoutjs shouldn't get in the way, since the documentation state that it doesn’t force you to use any one particular technique to load or save data

0
On

I just want to mention a minor point about using ProtoRPC from the client side, since there is not yet a fully developed client there. The main way to get ProtoRPC to use Json is to just make sure that your request content-type is 'application/json'. Otherwise, ProtoRPC might try to use the binary protobuf format.

Also, the documentation for ProtoRPC is a wee bit out of date. The examples show using ProtoRPC with a webapp based request handler. Instead you should use the newer wsgi based handler, especially if you are working on Python 2.7.

The WSGI handler is built in to ProtoRPC and the source code is here:

http://code.google.com/p/google-protorpc/source/browse/python/protorpc/wsgi/service.py#211

It works very similarly to the webapp handler except it's a little tricker to use it with existing webapp based application.