'Entry point for REST API
@param r: the S3Request
@param attr: controller arguments'

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

    try:
        person_id = int(r.get_vars['person_id'])
    except:
        raise HTTP(400, current.messages.BAD_REQUEST)
    self.settings = current.response.s3.crud
    sqlform = self._config('crud_form')
    self.sqlform = (sqlform if sqlform else S3SQLDefaultForm())
    self.data = None
    table = current.s3db.cr_shelter_registration
    query = ((table.deleted == False) & (table.person_id == person_id))
    exists = current.db(query).select(table.id, limitby=(0, 1)).first()
    if exists:
        r.method = 'update'
        self.record_id = exists.id
        output = self.update(r, **attr)
    else:
        r.method = 'create'
        self.data = {'person_id': person_id}
        output = self.create(r, **attr)
    return output
