'Main entry point for REST interface.
@param r: the S3Request instance
@param attr: controller parameters'

def apply_method(self, r, **attr):

    if (not self.permitted()):
        current.auth.permission.fail()
    output = {}
    representation = r.representation
    if (representation == 'html'):
        if (r.http in ('GET', 'POST')):
            output = self.registration_form(r, **attr)
        else:
            r.error(405, current.ERROR.BAD_METHOD)
    elif (representation == 'json'):
        if (r.http == 'POST'):
            output = self.registration_ajax(r, **attr)
        else:
            r.error(405, current.ERROR.BAD_METHOD)
    else:
        r.error(415, current.ERROR.BAD_FORMAT)
    return output
