# HG changeset patch # User Marcin Kuzminski # Date 1321837689 -7200 # Node ID fee9895fa46ed3731c94c44c8022426414a4e994 # Parent 54fda6ce9e98407a3c02868f753c48adab2ae958 changed API to match fully JSON-RPC specs diff -r 54fda6ce9e98 -r fee9895fa46e docs/api/api.rst --- a/docs/api/api.rst Mon Nov 21 02:53:17 2011 +0200 +++ b/docs/api/api.rst Mon Nov 21 03:08:09 2011 +0200 @@ -11,18 +11,20 @@ /_admin/api -All clients need to send JSON data in such format:: +All clients are required to send JSON-RPC spec JSON data:: - { + { + "id:, "api_key":"", "method":"", "args":{"":""} } Example call for autopulling remotes repos using curl:: - curl https://server.com/_admin/api -X POST -H 'content-type:text/plain' --data-binary '{"api_key":"xe7cdb2v278e4evbdf5vs04v832v0efvcbcve4a3","method":"pull","args":{"repo":"CPython"}}' + curl https://server.com/_admin/api -X POST -H 'content-type:text/plain' --data-binary '{"id":1,"api_key":"xe7cdb2v278e4evbdf5vs04v832v0efvcbcve4a3","method":"pull","args":{"repo":"CPython"}}' Simply provide + - *id* A value of any type, which is used to match the response with the request that it is replying to. - *api_key* for access and permission validation. - *method* is name of method to call - *args* is an key:value list of arguments to pass to method @@ -32,9 +34,10 @@ api_key can be found in your user account page -RhodeCode API will return always a JSON formatted answer:: +RhodeCode API will return always a JSON-RPC response:: - { + { + "id":, "result": "", "error": null } diff -r 54fda6ce9e98 -r fee9895fa46e rhodecode/controllers/api/__init__.py --- a/rhodecode/controllers/api/__init__.py Mon Nov 21 02:53:17 2011 +0200 +++ b/rhodecode/controllers/api/__init__.py Mon Nov 21 03:08:09 2011 +0200 @@ -50,6 +50,7 @@ def __init__(self, message): self.message = message + super(JSONRPCError, self).__init__() def __str__(self): return str(self.message) @@ -60,7 +61,7 @@ Generate a Response object with a JSON-RPC error body """ from pylons.controllers.util import Response - resp = Response(body=json.dumps(dict(result=None, error=message)), + resp = Response(body=json.dumps(dict(id=None, result=None, error=message)), status=code, content_type='application/json') return resp @@ -117,6 +118,7 @@ # check AUTH based on API KEY try: self._req_api_key = json_body['api_key'] + self._req_id = json_body['id'] self._req_method = json_body['method'] self._req_params = json_body['args'] log.debug('method: %s, params: %s', @@ -220,7 +222,8 @@ if self._error is not None: raw_response = None - response = dict(result=raw_response, error=self._error) + response = dict(id=self._req_id, result=raw_response, + error=self._error) try: return json.dumps(response)