示例#1
0
class ResourcePatchEndpoint(PatchEndpoint):
    """Patches a resource which is local to each instance of the app.
    """

    _uri = "/resource"
    _route_name = "resource_patch"

    _resource = DebugResource("resource patch.")
    _returns = DebugResource("app resource.")

    def _handle_patch(self, context, patch):
        data = dict(RESOURCE)
        patch.apply_to_dict(data)
        RESOURCE.update(data)
        return dict(RESOURCE)
示例#2
0
class GetResourceEndpoint(Endpoint):
    """Returns the 'resource' as it exists in memory.
    """

    _uri = "/resource"
    _http_method = 'GET'
    _route_name = "resource_get"

    _returns = DebugResource("app resource.")

    def _handle(self, context):
        return dict(RESOURCE)
示例#3
0
class ResetResourceEndpoint(Endpoint):
    """Returns the 'resource' as it exists in memory.
    """

    _uri = "/resource/reset"
    _http_method = 'POST'
    _route_name = "resource_reset"

    _returns = DebugResource("app resource.")

    def _handle(self, context):
        RESOURCE.clear()
        RESOURCE.update(BASE_RESOURCE)
        return dict(RESOURCE)
示例#4
0
class RouteArgEndpoint(Endpoint):
    """Returns the arguments as provided from URI.
    """

    _uri = "/arg_test/<arg_a>/<arg_b>"
    _http_method = 'GET'
    _route_name = "arg_test"

    _returns = DebugResource("app resource.")

    def _handle(self, context):
        arg_a = context.route_kwargs.get('arg_a', 'no')
        arg_b = context.route_kwargs.get('arg_b', 'no')
        return {"arg_a": arg_a, "arg_b": arg_b}