joostvunderink / angular-jsonrpc-client

A JSON-RPC 2.0 client for AngularJS
MIT License
26 stars 20 forks source link

Lack of support multiple urls. #2

Closed alex-mos closed 9 years ago

alex-mos commented 9 years ago

I need to use multiple json-rpc servers (for example: authorization and rating). It's not possible in current library. Please, add support of url as request parameter. Example:

jsonrpc.request('get_sessionid', 'http://first-server.com' []);

jsonrpc.request('get_rating', 'http://second-server.com' [
    1
    , "entry"
    , "-1:1"
    , "service-faq"
]);
joostvunderink commented 9 years ago

This is a good idea, and one I have been thinking about myself as well. I'll add this feature soon.

joostvunderink commented 9 years ago

This request has been implemented.

Here is how to use it:

    .module('MyApp', ['angular-jsonrpc-client'])
    .config(function(jsonrpcConfigProvider) {
        jsonrpcConfigProvider.set({
            servers: [
                {
                    name: 'first',
                    url: 'http://example.com:8080/rpc'
                },
                {
                    name: 'second',
                    url: 'http://example.net:4444/api'
                }
            ]
        });
    })
    .controller('MyController', ['$scope', 'jsonrpc', function($scope, jsonrpc) {
        jsonrpc.request('first', 'version', {})
            .then(function(result) {
                $scope.result = result;
            })
            .catch(function(error) {
                $scope.error = error;
            });
    }]);

Enjoy!

alex-mos commented 9 years ago

Thank you. Hunky-dory!