cloudsync.oauth.apiserver.ApiServer

class cloudsync.oauth.apiserver.ApiServer(addr: str, port: int, headers=None, log_level=<ApiServerLogLevel.ARGS: 2>, allow_reuse=False)

from apiserver import ApiServer, ApiError, api_route

Create your handlers by inheriting from ApiServer and tagging them with @api_route(“/path”).

Alternately you can use the ApiServer() directly, and call add_handler(“path”, function)

Raise errors by raising ApiError(code, message, description=None)

Return responses by simply returning a dict() or str() object

Parameter to handlers is a dict()

Query arguments are shoved into the dict via urllib.parse_qs

add_route(path, meth, content_type='application/json')

Add a new route handler.

address()

Get my ip address

port()

Get my port

serve_forever()

Start listening and responding.

server_close()

Closes the server and joins all threads

shutdown()

Stops the current server, if started

uri(path='/', hostname=None)

Make a URI pointing at myself

class cloudsync.oauth.apiserver.ApiError(code, msg=None, desc=None, json=None)

User can raise an ApiError in order to abort processing and return something other than ‘200’ to the web client.

Args:

code: status code msg: message to show desc: description of the error json: json to return, instead of any error descriptions

classmethod from_json(error_json)
cloudsync.oauth.apiserver.api_route(path)

Decorator for handling specific urls.

Args:

path: the route to handle

If this ends in a ‘/’, it will handle all routes starting with that path.