Search code examples
javascriptjquerygoogle-app-enginejson-rpcprotorpc

Make JSON-RPC jQuery plugin work with GAE ProtoRPC


I am trying to make these two libraries work together. But I am not sure they can connect out of the box. Before using JSON-RPC plugin I did it successfully with standard $.ajax functionality. Could you please give me some short example of how a client-side function should look and the entry point for this on GAE side.

Or maybe there should be a special ProtoRPC jQuery library created to make this work easily?

JSON-RPC plugin homepage


Solution

  • ProtoRPC doesn't use the JSON-RPC message format. It uses a simpler format where each API method provides its own endpoint, rather than one endpoint that takes a method name as part of the request dictionary.

    Here's the example they provide for $.ajax:

    $.ajax({url: '/hello.hello',
              type: 'POST',
              contentType: 'application/json',
              data: '{ my_name: Bob }',
              dataType: 'json',
              success: function(response) {
                // The response is { hello: "Hello there, Bob!" }
                alert(response.hello);
              }
             });
    

    Do you really need a special jQuery library for this? I'm not sure it can get much simpler.