Maybe this is stupid question but if I implement http patch, is there no good way to reduce the number of possible cases without exploding into a large number (2^n) of different cases depending on which parameters are present or null/None.

For a simple example consider an SQL table named "User" with columns FirstName, LastName and Email. Then there will be 6 (2^3) different cases which a must implement in my REST API logic for only three properties i.e.

 1. FirstName=NULL, LastName="<value1>", Email="<value2>"
 2. FirstName="<value0>", LastName=NULL, Email="<value2>"  
 3. FirstName="<value0>", LastName=NULL, Email=NULL
 4. FirstName=NULL, LastName="<value1>", Email=NULL
 5. FirstName="<value0>", LastName="<value1>", Email="<value2>"
 6. FirstName=NULL, LastName=NULL, Email=NULL

The above will become quite a lot of code in order to handle all possible cases and this wa only for three properties. Did I misunderstood or is there a better way?

  • 2
    Actually, 2^3 = 8. – herby Apr 4 at 12:17

There is nothing in HTTP PATCH that requires your code to be structured as

IF field1 has value AND field2 is NULL AND field3 is absent THEN do something
IF field1 has value AND field2 has value AND field3 is absent THEN do something else

To get more maintainable code, you can also structure it like

get related entity
process field1 as indicated in the request
process field2 as indicated in the request
process field3 as indicated in the request
store the updated entity

That way the code scales linearly with the number of fields in the entity instead of explosively.

For testing, you should still test every combination but there you can use data-driven testing techniques to keep it manageable.


You should test all those cases.

You can completely imagine a single field being problematic with null or date parsing or something. Although many people would skip them, simply testing a fully populated user and a completely null user.

You can reduce the code required to test them all with data driven tests

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.