pyeve / eve

REST API framework designed for human beings
https://python-eve.org
Other
6.69k stars 746 forks source link

Replace vs Merge Update on PATCH #1496

Open ghost opened 1 year ago

ghost commented 1 year ago

Feature Request

Providing a header that will allow a PATCH request to replace a key value instead of using PUT, PUT replaces fields I want to preserve and leave unchangeable.

Unless this can be achieved in another way

Expected Behavior

# 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': {
    'three': 3,
    'four': 4
  }
}

Actual Behavior

Tell us what happens instead.

# 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
  }
}

Environment