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)
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)
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)
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}