On Jun 30, 3:59 pm, Mike Orr <sluggos...@gmail.com> wrote: > On Wed, Jun 30, 2010 at 12:01 PM, j_king <j.kenneth.k...@gmail.com> wrote: > > Hello everyone, > > > Just wanted to let everyone know about a pylons project of mine: > > >http://bitbucket.org/agentultra/pylons/overview > > > I created a new JSONRPCController class that will allow pylons users > > to build JSON-RPC based services for their applications. > > > I'd like to get some feedback from the community if that's possible > > before I initiate a pull-request. Does the code meet community > > conventions? Are there any glaring bugs I missed? > > I just wrote some ad hoc web services with JSON output. Could you > explain a bit what advantage JSON-RPC would have? I looked at the diff > and have no comments on the API since I'm not sure I'm qualified to > judge. The only thing I'm hesitant about is the import to > pylons.controllers. That would depend on how central and permanent we > feel this controller would be.
JSON-RPC can be thought of along the lines of XML-RPC. It's a transport format to facilitate remote procedure calls between a client and server. The difference between XML-RPC and JSON-RPC is pretty obvious: instead of XML, we're using JSON. There are some cosmetic differences in the semantics of the specifications and if you're interested you can read up on the JSON-RPC spec here: http://json-rpc.org/ One feature of JSON-RPC that I think Pylons can benefit from is JSON itself. It's a very common transport format for speaking with browsers. As AJAX client applications become more common I think Pylons will have to get better at speaking in JSON rather than HTML (or in some cases, XML as with the XMLRPCController already included). > Could you give a concrete example of a controller and routing that > uses this? That would help show its benefits, and would be needed for > the docs anyway. -- routing.py map.connect('/users', controller='users') -- controllers/users.py # various imports from pylons.controllers import JSONRPCController, JSONRPCError class UsersController(JSONRPCController): users = dict(1='john', 2='sally') def view(self, id): try: return self.users[id] except KeyError, e: raise JSONRPCError, "Invalid value: %r" % id --- Then your client application can call your JSONRPCController methods as RPCs. >>> from jsonrpc import ServiceProxy >>> s = ServiceProxy('http://localhost:5000/users') >>> s.view(1) john >>> s.view('snorgleplax') jsonrpc.proxy.JSONRPCException: 'Invalid value: snorgleplax' > Here's my ad hoc web service API in one application. Would JSON-RPC be > of benefit here? > > # /chemical/{id}.json > # Return chemical properties as a JSON dict. > > # /react/{id}.json > # Return reactive group properties as a JSON dict. > > # /reactivity.json?id=CH1234&id=RG50&id=CH5678 > # Return a JSON dict describing the reactivity if the specified > # chemicals and/or reactive groups mixed. > > The latter service has been requested by users, although we're not > sure exactly what kind of client program would issue the queries. The > other two services are speculation, based on the idea that "if you > build it, they will come" (i.e., realize they want it). Essentially RPC is an abstraction over the string-based query interface we're used to. It allows you or your users to develop client- side code that calls methods on your services as if they were local functions. So instead of listing your application API as a list of query strings, you can define it in terms of methods and parameters. XML-RPC has been doing it for years, JSON-RPC is simply better at doing it for web-applications which is what Pylons is primarily used for. In the example case, you could publish a JSON-RPC service at '/ chemicals'. Client code that can speak JSON-RPC can then set up a service proxy object and call methods on that object using their native language's calling conventions. My use-case is pyjamas. They've recently implemented a JSON-RPC client in the framework. This will allow me to write UI code in Python using RPC calls that look like regular python objects. Of course it all compiles out to javascript in the end, but I didn't have to write a single line of javascript or query a bunch of URLs and write code to serialize/deserialize the results, etc. The source all looks like a single unified Python application. Does that help? -- You received this message because you are subscribed to the Google Groups "pylons-devel" group. To post to this group, send email to pylons-de...@googlegroups.com. To unsubscribe from this group, send email to pylons-devel+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-devel?hl=en.