def add_resource(<EOL>self,<EOL>base_rule,<EOL>base_view,<EOL>alternate_view=None,<EOL>alternate_rule=None,<EOL>id_rule=None,<EOL>app=None,<EOL>):
if alternate_view:<EOL><INDENT>if not alternate_rule:<EOL><INDENT>id_rule = id_rule or DEFAULT_ID_RULE<EOL>alternate_rule = posixpath.join(base_rule, id_rule)<EOL><DEDENT>else:<EOL><INDENT>assert id_rule is None<EOL><DEDENT><DEDENT>else:<EOL><INDENT>assert alternate_rule is None<EOL>assert id_rule is None<EOL><DEDENT>app = self._get_app(app)<EOL>endpoint = self._get_endpoint(base_view, alternate_view)<EOL>views = app.extensions['<STR_LIT>'].views<EOL>base_rule_full = '<STR_LIT>'.format(self.prefix, base_rule)<EOL>base_view_func = base_view.as_view(endpoint)<EOL>if not alternate_view:<EOL><INDENT>app.add_url_rule(base_rule_full, view_func=base_view_func)<EOL>views[base_view] = Resource(base_view, base_rule_full)<EOL>return<EOL><DEDENT>alternate_rule_full = '<STR_LIT>'.format(self.prefix, alternate_rule)<EOL>alternate_view_func = alternate_view.as_view(endpoint)<EOL>@functools.wraps(base_view_func)<EOL>def view_func(*args, **kwargs):<EOL><INDENT>if flask.request.url_rule.rule == base_rule_full:<EOL><INDENT>return base_view_func(*args, **kwargs)<EOL><DEDENT>else:<EOL><INDENT>return alternate_view_func(*args, **kwargs)<EOL><DEDENT><DEDENT>app.add_url_rule(<EOL>base_rule_full, view_func=view_func, endpoint=endpoint,<EOL>methods=base_view.methods,<EOL>)<EOL>app.add_url_rule(<EOL>alternate_rule_full, view_func=view_func, endpoint=endpoint,<EOL>methods=alternate_view.methods,<EOL>)<EOL>views[base_view] = Resource(base_view, base_rule_full)<EOL>views[alternate_view] = Resource(alternate_view, alternate_rule_full)<EOL>
Add route or routes for a resource.

        :param str base_rule: The URL rule for the resource. This will be
            prefixed by the API prefix.
        :param base_view: Class-based view for the resource.
        :param alternate_view: If specified, an alternate class-based view for
            the resource. Usually, this will be a detail view, when the base
            view is a list view.
        :param alternate_rule: If specified, the URL rule for the alternate
            view. This will be prefixed by the API prefix. This is mutually
            exclusive with id_rule, and must not be specified if alternate_view
            is not specified.
        :type alternate_rule: str or None
        :param id_rule: If specified, a suffix to append to base_rule to get
            the alternate view URL rule. If alternate_view is specified, and
            alternate_rule is not, then this defaults to '<id>'. This is
            mutually exclusive with alternate_rule, and must not be specified
            if alternate_view is not specified.
        :type id_rule: str or None
        :param app: If specified, the application to which to add the route(s).
            Otherwise, this will be the bound application, if present.