def include_extra_routes(self, schema_url=None, docs_url=None, static_url=None): extra_routes = [] from stark.server.handlers import serve_documentation, serve_schema, serve_static_wsgi if schema_url: extra_routes += [ Route(schema_url, method='GET', handler=serve_schema, documented=False) ] if docs_url: extra_routes += [ Route(docs_url, method='GET', handler=serve_documentation, documented=False) ] if static_url: static_url = static_url.rstrip('/') + '/{+filename}' extra_routes += [ Route(static_url, method='GET', handler=serve_static_wsgi, name='static', documented=False, standalone=True) ] return extra_routes
def make_create_route(resource: str, handler: typing.Union[str, typing.Callable], baseurl: str = None, documented: bool = True, standalone: bool = False): if baseurl is None: baseurl = resource url = "/" + baseurl.lstrip("/") return Route(url=url, method="POST", handler=find_handler(handler), documented=documented, standalone=standalone, tags=[resource, "#create"])
def make_destroy_route(resource: str, handler: typing.Union[str, typing.Callable], lookup_param: str, baseurl: str = None, documented: bool = True, standalone: bool = False): if baseurl is None: baseurl = resource url = "/" + ("%s/{%s}" % (baseurl, lookup_param)).lstrip("/") return Route(url=url, method="DELETE", handler=find_handler(handler), documented=documented, standalone=standalone, tags=[resource, "#delete"])
def make_action_route(resource: str, handler: typing.Union[str, typing.Callable], method: str, action: str = None, lookup_param: str = None, baseurl: str = None, documented: bool = True, standalone: bool = False): if baseurl is None: baseurl = resource handler = find_handler(handler) if action is None: action = handler.__name__ if lookup_param: url = "/" + ("%s/{%s}/%s" % (baseurl, lookup_param, action)).lstrip("/") else: url = "/" + ("%s/%s" % (baseurl, action)).lstrip("/") return Route(url=url, method=method, handler=handler, documented=documented, standalone=standalone, tags=[resource, "#action"])