문제

I have an API in C# that won't map to JSON-RPC due to the fact that JSON-RPC is Procedurally oriented. How in JSON-RPC would you represent an Object Oriented API?
I can of course use the JSON-RPC extensions so that the request would look like:

{ "jsonrpc":"2.0", method:"ObjectName.Method", "params":[], "id": 1 }

But it feels kinda hackish and also requires a lot of work to define. I can also include it as a parameter but again it just doesn't feel right.
Is there a best practice regarding working against an Object Oriented API using JSON-RPC?

도움이 되었습니까?

해결책

JSON-RPC is JSON Remote Procedure Call and by default procedure oriented.

However if you work over HTTP you can see each RPC service as object. I.e. if you access /foo/bar and call beep over JSON-RPC over HTTP then you call beep method of foo service of bar object.

Otherwise you may do it the way all OOP mapped over procedure calls:

foo.bar(x1,x2) -> bar(foo,x1,x2) 

Where foo is "pointer" to object, for RPC it may be object UUID. (That is how it is actually done in some RPCS).

So you call

f=new integer(0);
f.add(10);
f.add(20);
x=f.get();
delete f;

Goes to:

client:   new("integer",0)
server:   return "23ab3cb45"
client:   add("23ab3cb45",10);
client:   add("23ab3cb45",20);
client:   get("23ab3cb45");
server:   return 30
client:   delete("23ab3cb45");
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top