Python Eve,如何用PATCH请求替换'dict'

时间:2017-01-11 16:35:32

标签: python mongodb eve

我正在使用Python Eve,这很棒,但我遇到了问题,不确定是否有解决方案。

我在这个架构中有一个'fields'字典:

'profiles': {
  'fields': {
    'type': 'dict',
    'default': {}
  }
}

我希望能够PATCH更新'fields'字段,但问题是PATCH请求永远不会删除'fields'中的任何字段,但是我不能使用PUT命令或者我的所有其他配置文件字段(上面未显示)将消失。

我尝试使用像这样的子资源:

'profile-fields': {
  'schema': {
    'fields': {
      'type': 'dict',
      'default': {}
    }
  },
  'datasource': {
    'source': 'profiles',
    'projection': { 'fields': 1 }
  }
},

但正如Python Eve文档所述:

  

请注意,POST和PATCH方法仍然允许操作整个架构   http://python-eve.org/config.html#multiple-api-endpoints-one-datasource

任何人都知道这样做的方法吗?

例如:

# Create a record
POST /api/profiles
{
  'name': 'Test',
  'fields': {
    'one': 1,
    'two': 2
  }
}
# => { _created: 'blah', _id: '123456' }

# then update fields with a PATCH request
PATCH /api/profiles/123456
{
  'fields': {
    'three': 3,
    'four': 4
  }
}

# then get the updated record
GET /api/profiles/123456
# RESPONSE
{
  '_id': '123456',
  'name': 'Test',
  'fields': {
    'one': 1,
    'two': 2,
    'three': 3,
    'four': 4
  }
}

我刚刚承认使用了PUT请求并再次发回整个对象,我猜这是可以的,只是认为可能有办法做到这一点。

0 个答案:

没有答案