2

I'm in the middle of trying to create a django website to access data in a MySQL database. The intenion is to also create a UI in Dojo (javascript). Also I would like the django backend to also provide webservices (RPC for python functions) to allow access to the MySQL database remotely. So for example, if someone wants to use Perl scripts to access the database (and possible other additional functionality like calculations based off of data in the database) they can do so in their native language (Perl).

Now ideally, the web services API is the same for javascript as well as another remote service that wants to access these services. I've found that JSON-RPC is a good way to go for this, as there is typically built in support for this in javascript in addition to the numerous additional benefits. Also a lot of people seem to be preferring SOAP to JSON.

I've seen several ways to do this:

1) Create a unique URI for each function that you would like to access: https://code.djangoproject.com/wiki/JSONRPCServerMiddleware

2) Create one point of access, and pass the method name in the JSON package. In this particular example an SMD is automatically generated. https://code.djangoproject.com/wiki/Jsonrpc

The issue with (1) is that if there are many functions to be accessed, then there will be many URI's that will be used. This does not seem like an elegant solution. The issue with (2) is that I need to compare functions against a list of all functions. Again this is not an elegant solution either.

Is there no way that we can take the advantages of (1) and (2) to create an interface such that: - Only one URI is used as a point of access - Functions are called directly (without having to be compared against a list of functions)

Any help with this will be really appreciated. Thanks!

4

3 回答 3

1

what about using REST API?

于 2011-08-17T18:35:07.210 回答
1

进行比较的一种可能性是使用这样的字典:

def func1(someparams):
    #do something
    return True

def func2(sameparams):
    #do something else
    return True


{'func1': func1,
 'func2': func2}

然后当你得到 API 调用时,你在 dict 中查找它并从那里调用,任何不在 dict 中的函数都会得到 404 处理程序。

于 2011-08-19T00:00:22.603 回答
0

It sounds like what you really want is a RPC server of some kind (SOAP, say, using soaplib) that is written in python and uses your application's data model, and what ever other APIs you have constructed to handle the business logic.

So I might implement the web service with soaplib, and have it call into the datamodel and other python modules as needed. People wanting to access your web application's data would use the SOAP service, but the web application would use the underlying datamodel + apis (for speed, your web app could use the SOAP service too, but it would be slower).

于 2011-09-06T17:34:32.900 回答