Is there a good way to automatically generate javascript client code from server side python server

Basically I want to be able to:

  • Write some functions in python (with a minimum amount of additional metadata)
  • Include these features in the web service (with minimal effort / boiler plate).
  • Automatically create some javascript functions / objects for rpc (this should prevent me from doing as many stupid things as possible, such as nebula method names, forgetting the method names, passing the wrong number of arguments)

Example

python:

def hello_world(): return "Hello world" 

JavaScript:

 ... <!-- This file is automatically generated (either dynamically or statically) --> <script src="http://myurl.com/webservice/client_side_javascript"> </script> ... <script> $('#button').click(function () { hello_world(function (data){ $('#label').text(data))) } </script> 

Several studies have shown me some approaches that are approaching this:

  • Automatically generating json-rpc services from functions with a small python code table code and then using jquery and json to make calls (it’s still easy to make a mistake with the method names) you still need to know about the URLs when calling, it’s very annoying to write these calls yourself in the firebug shell)

  • Using a library such as soaplib to generate wsdl from python (by adding extensive type information). And then somehow convert this to javascript (not sure if there is even a library for this)

But are there any approaches closer to what I want?

+4
source share
2 answers

Yes, there are pajamas . Some people rate this as " GWT for Python"

+6
source

It seems that using the javascript XML RPC client (there is a jquery plugin for this) along with the XML RPC server is a good way.

The jquery plugin will introspect your rpc service and populate the method names, which makes it impossible for the method name to be called incorrectly without an early warning. However, it will not check the number of arguments you pass, or their type.

It seems that there is no such support for introspection on json rpc (or rather, there is no agreed standard). This approach can also be used with django.

I compiled an example code and uploaded it here (I hope that a link to one blog post is not considered a terrible form - a brief search on the Internet did not seem to suggest that it was ...)

0
source

Source: https://habr.com/ru/post/1305494/


All Articles