Giter VIP home page Giter VIP logo

Comments (9)

ryanhollister avatar ryanhollister commented on August 18, 2024

Nevermind, no more than 30 seconds after submitting this I realized that pyramid_rpc is taking the arguments a step further than I expected.

For example, if the request is:

{"jsonrpc":"2.0","method":"service_render","id":1,"params":{"test":"1","test2":"2"}}

then the method signature will need to be:

@jsonrpc_method(endpoint='api')
def service_render(request, data, data2):

and then pyramid_rpc will map "1" to data and "2" to data2.

This works, but is slightly unintuitive. I will propose some additional documentation around this.

Thank you and hopefully this issue will help someone else in the future.

from pyramid_rpc.

ryanhollister avatar ryanhollister commented on August 18, 2024

I am making a mess of this issue now, but it still appears to not be working correctly. Even with my understanding from my comment above, the values for data and data2 are not the values of the named parameters but rather the name.

As I said the values were "1" and "2" for data and data2 respectively. This is not happening, the values for data and data2 are actually "test" and "test2"

Sorry for the confusion but I think I have identified the problem. Hopefully we can find a solution.

from pyramid_rpc.

ryanhollister avatar ryanhollister commented on August 18, 2024

Ok, last post I promise :-)

So it turns out pyramid_rpc is SUPER smart.

It maps the named parameters to their associated parameter names... Meaning in order to call:

def service_render(request, data, data2):

the params should be:

{"jsonrpc":"2.0","method":"service_render","id":1,"params":{"data":"1","data2":"2"}}

Then the values are correct inside the method.

Sorry for the mess.

from pyramid_rpc.

mmerickel avatar mmerickel commented on August 18, 2024

Named parameters are not supported with pyramid_rpc right now. The fact that its working for you is lucky because the params dict is unordered.

I haven't seen a compelling reason to support named parameters. In all of the servers I've looked at while implementing JSON-RPC I have never seen one that supported it. If you know of one that does, let me know and I'll think about it. Same goes for clients. XML-RPC doesn't support them and gets along just fine because in reality it is RPC where you are calling a function with a defined signature, so it's on you (the client) to provide the arguments to match the signature in the correct order.

from pyramid_rpc.

ryanhollister avatar ryanhollister commented on August 18, 2024

thank you for the follow up mmerickel.

Named parameters isn't that important to me. I think the only reason I ventured down that path was because I was getting inconsistent or unintended data being passed to my json-rpc exposed functions.

As I was saying before, I was getting the name of the parameters and not the values.

I would propose changing line 126 in jsonrpc.py from:

request.rpc_args = tuple(body.get('params', []))

to

request.rpc_args = tuple(body.get('params', []).values())

I very well may not understand the full repercussions of this change, but in my anecdotal scenario it fixed my issues.

from pyramid_rpc.

mmerickel avatar mmerickel commented on August 18, 2024

I will think about adding support for named parameters, but like I said: it's not supported right now. Thus, you should not be sending a dictionary as the params argument.

from pyramid_rpc.

epegzz avatar epegzz commented on August 18, 2024

I spent about one hour today to figure out, why my named parameters sent by a java-jsonrpc-client do not make it to my rpc_method in pyramid. Actually i came here to have a look at the code, but then found this Issue here first.

Since named parameters are supported in the spec proposal ( http://en.wikipedia.org/wiki/JSON-RPC#Version_2.0_.28Specification_Proposal.29 ) I would love to see them supported by pyramid_rpc.

from pyramid_rpc.

epegzz avatar epegzz commented on August 18, 2024

implemented in pull request #17

from pyramid_rpc.

mmerickel avatar mmerickel commented on August 18, 2024

The trunk now supports named parameters. This will be in the next release.

from pyramid_rpc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.