[erlang-questions] json-rpc erlang adding new procedure/ method

Tony Garnock-Jones <>
Fri Aug 1 14:59:24 CEST 2008


Hi Mark,

You also need to extend the service description record passed in to 
rfc4627_jsonrpc:register_service:

     rfc4627_jsonrpc:register_service
       (Pid,
        rfc4627_jsonrpc:service(<<"test">>,
                    <<"urn:uuid:afe1b4b5-23b0-4964-a74a-9168535c96b2">>,
                    <<"1.0">>,
                    [#service_proc{name = <<"test_proc">>,
                           idempotent = true,
                           params = [#service_proc_param{name = <<"value">>,
                                         type = <<"str">>}]},
                 #service_proc{name = <<"new_proc">>,
                           idempotent = true,
                           params = [#service_proc_param{name = <<"value">>,
                                         type = <<"str">>}]}])).

The service description is used by the Javascript JSON-RPC client to 
install methods (test_proc, new_proc) on the Javascript object that is 
proxying for the JSON-RPC service. If a method is not described in the 
description record, no method stub will be generated for that method on 
the Javascript side.

Regards,
   Tony


mark wrote:
> I am trying to get json-rpc working in erlang, and got the
> test_jsonrpc_inets example working. from here
> http://hg.opensource.lshift.net/erlang-rfc4627/raw-file/tip/doc/index.html
> 
> I am trying to add another procedure new_proc similar to test_proc,
> and if I add these two lines to the test_jsonrpc_inets.erl, it does
> not work, and it says method not supported on my rpc client.
> can you tell me what is the correct way to add another procedure?
> thanks
> 
> handle_call({jsonrpc, <<"test_proc">>, _ModData, [Value]}, _From, State) ->
>     {reply, {result, <<"ErlangServer: ", Value/binary>>}, State};
> handle_call({jsonrpc, <<"new_proc">>, _ModData, [Value]}, _From, State) ->
>     {reply, {result, <<"NewMessage: ", Value/binary>>}, State}.
> 
> 
> 
> error from my json-rpc client.
>>>> s.test_proc("hello")
> {u'version': u'1.1', u'id': 5, u'result': u'ErlangServer: hello'}
>>>> s.new_proc("hello")
> {u'version': u'1.1', u'id': 6, u'error': {u'message': u'Procedure not
> found', u'code': 404, u'name': u'JSONRPCError', u'error':
> [u'http://localhost:5671/rpc/test', u'new_proc']}}
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
> 


-- 
  [][][] Tony Garnock-Jones     | Mob: +44 (0)7905 974 211
    [][] LShift Ltd             | Tel: +44 (0)20 7729 7060
  []  [] http://www.lshift.net/ | Email: 



More information about the erlang-questions mailing list