def configure_relation(graph, ns, mappings, path_prefix=""): """ Register relation endpoint(s) between two resources. """ ns = Namespace.make(ns, path=path_prefix) convention = RelationConvention(graph) convention.configure(ns, mappings)
def configure_crud(graph, ns, mappings, path_prefix=""): """ Register CRUD endpoints for a resource object. :param mappings: a dictionary from operations to tuple, where each tuple contains the target function and zero or more marshmallow schemas according to the signature of the "register_<foo>_endpoint" functions Example mapping: { Operation.Create: (create_foo, NewFooSchema(), FooSchema()), Operation.Delete: (delete_foo,), Operation.Retrieve: (retrieve_foo, FooSchema()), } """ ns = Namespace.make(ns, path=path_prefix) convention = CRUDConvention(graph) convention.configure(ns, mappings)
def for_(cls, operation, ns, qs=None, type=None, allow_templates=False, **kwargs): """ Create a link to an operation on a resource object. Supports link templating if enabled by making a best guess as to the URI template construction. See also [RFC 6570]( https://tools.ietf.org/html/rfc6570). :param operation: the operation :param ns: the namespace :param qs: an optional query string (e.g. for paging) :param type: an optional link type :param allow_templates: whether generated links are allowed to contain templates :param kwargs: optional endpoint expansion arguments (e.g. for URI parameters) :raises BuildError: if link templating is needed and disallowed """ # ensure that we actually have a Namespace; many legacy code paths use strings or tuples ns = Namespace.make(ns) try: href, templated = ns.href_for(operation, qs=qs, **kwargs), False except BuildError as error: if not allow_templates: raise uri_templates = { argument: "{{{}}}".format(argument) for argument in error.suggested.arguments } kwargs.update(uri_templates) href, templated = ns.href_for(operation, qs=qs, **kwargs), True return cls( href=href, type=type, templated=templated, )