'Entry point for the REST interface
@param r: the S3Request
@param method: the method established by the REST interface
@param widget_id: widget ID
@param attr: dict of parameters for the method handler
@return: output object to send to the view'

def __call__(self, r, method=None, widget_id=None, **attr):

    self.request = r
    response = current.response
    self.download_url = response.s3.download_url
    self.next = None
    if (method is not None):
        self.method = method
    else:
        self.method = r.method
    if r.component:
        component = r.component
        resource = component
        self.record_id = self._record_id(r)
        if (not self.method):
            if (component.multiple and (not r.component_id)):
                self.method = 'list'
            else:
                self.method = 'read'
        if component.link:
            actuate_link = r.actuate_link()
            if (not actuate_link):
                resource = component.link
    else:
        self.record_id = r.id
        resource = r.resource
        if (not self.method):
            if (r.id or (r.method in ('read', 'display'))):
                self.method = 'read'
            else:
                self.method = 'list'
    self.prefix = resource.prefix
    self.name = resource.name
    self.tablename = resource.tablename
    self.table = resource.table
    self.resource = resource
    if (self.method == '_init'):
        return None
    if r.interactive:
        hide_filter = attr.get('hide_filter')
        if isinstance(hide_filter, dict):
            component_name = r.component_name
            if (component_name in hide_filter):
                hide_filter = hide_filter[component_name]
            elif ('_default' in hide_filter):
                hide_filter = hide_filter['_default']
            else:
                hide_filter = None
        if (hide_filter is None):
            hide_filter = (r.component is not None)
        self.hide_filter = hide_filter
    else:
        self.hide_filter = True
    if (widget_id and hasattr(self, 'widget')):
        output = self.widget(r, method=self.method, widget_id=widget_id, **attr)
    else:
        output = self.apply_method(r, **attr)
        if (self.next and resource.lastid):
            self.next = str(self.next)
            placeholder = '%5Bid%5D'
            self.next = self.next.replace(placeholder, resource.lastid)
            placeholder = '[id]'
            self.next = self.next.replace(placeholder, resource.lastid)
        if (not response.error):
            r.next = self.next
        self._extend_view(output, r, **attr)
    return output
