Pyjamas

16 views
Skip to first unread message

Nicolas Pinault

unread,
Feb 6, 2012, 4:31:46 PM2/6/12
to Nagare users
Hello Alain,

I've tried to use Pyjamas with Nagare today but I was not successful. I am not sure it is possible. If you know a way to use Pyjamas with Nagare, please let me know.

Best regards,
Nicolas

apoirier

unread,
Feb 7, 2012, 11:39:15 AM2/7/12
to Nagare users
Hi Nicolas,

On Feb 6, 10:31 pm, Nicolas Pinault <nico...@famillepinault.fr> wrote:
> Hello Alain,
>
> I've tried to use Pyjamas with Nagare today but I was not successful. I
> am not sure it is possible. If you know a way to use Pyjamas with
> Nagare, please let me know.

Pyjamas being a port of GWT, a Pyjamas application, once translated to
javascript, fully runs on the client. Then it can send AJAX requests
to the server to obtain datas. The `jsonrpc` examples in the Pyjamas
distribution shows how to send such JSON-RPC formatted AJAX requests.

So, one way for a Pyjamas application to talk to a Nagare application
is to set significative URL (http://naga.re/trac/wiki/RestfulUrl) to
handle the JSON-RPC calls. Here is a Nagare application that can
communicate with the Pyjamas `jsonrpc` example:


import json
from webob import exc
from nagare import presentation

# Path to the `output` directory of the Pyjamas `jsonrpc` example
PYJAMAS_JSONRPC_EXAMPLE = '/tmp/pyjamas-0.7/examples/jsonrpc/output/'

class Pyjamas(object):
def echo(self, s):
return s

def reverse(self, s):
return s[::-1]

def uppercase(self, s):
return s.upper()

def lowercase(self, s):
return s.lower()

# Significative URL to dispatch the JSON-RPC calls
@presentation.init_for(Pyjamas, 'len(url)==2 and url[0]=="services"')
def init(self, url, comp, http_method, request):
payload = request.json_body
r = getattr(self, payload['method'])(*payload['params'])

response = exc.HTTPOk()
response.body = json.dumps({'result' : r, 'id' : payload['id'],
'jsonrpc' : '2.0' })
response.content_type = 'application/json'
raise response

# ---------------------------------------------------------------

# Significative URL to proxy the Pyjamas `jsonrpc` files
# (normally done by the front HTTP server)
@presentation.init_for(Pyjamas, 'len(url)==1 and url[0]!="services"')
def init(self, url, comp, http_method, request):
with open(PYJAMAS_JSONRPC_EXAMPLE+url[0]) as f:
response = exc.HTTPOk()
response.body = f.read()
raise response

# ---------------------------------------------------------------

app = Pyjamas


Best regards,
Alain

Nicolas Pinault

unread,
Feb 7, 2012, 12:09:26 PM2/7/12
to nagare...@googlegroups.com
Alain,

Thanks for your help.

Best regards,
Nicolas

Reply all
Reply to author
Forward
0 new messages