'API entry point
@param r: the S3Request instance
@param attr: controller attributes for the request'

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

    if (r.http in ('GET', 'POST', 'DELETE')):
        if r.record:
            self.settings = current.response.s3.crud
            self.sqlform = sqlform = self._config('crud_form')
            if (not sqlform):
                from s3forms import S3SQLDefaultForm
                self.sqlform = S3SQLDefaultForm()
            output = self.profile(r, **attr)
            return output
        elif (r.representation not in ('dl', 'aadata')):
            redirect(r.url(method=''))
        else:
            r.error(404, current.ERROR.BAD_RECORD)
    else:
        r.error(405, current.ERROR.BAD_METHOD)
