java - Partial update in an API -
i have use case in need update of fields of api.
example:
if api updatestudentdetails
, input takes is:
name cgpa address hostel name
here want update name
only.
1 way fields , update name
, call updatestudentdetails
fields. requires 1 read call @ client side prior update call.
other ways are:
1. ask client needs updated. in case api signature might like:
name cgpa address hostel name studentdetailstoupdate
here studentdetailstoupdate
list of enums , enum can have values name, cgpa, address, hostel_name
. based on enum list provided client can update respective fields.
- take actions based on field value. in case if cgpa passed
null
client not want update , ifname
non-null
client wants update.
i not able find major pros , cons in above 2 approaches , seek community’s guidance. bit inclined towards first approach intention clear me , not taking decisions based on field values might possible other language might not have concept of null.
i go second option.
if go first, you'd have write code checking argument needs updated.
what nice option option 3 :) use builder pattern (you can google it's used pattern). way can chain values need updated , update them if aren't null.
you'll like
updatestudentdetails details = new updatestudentsbuilder().withname("tony").withhostelname("some nice hostel").build();
Comments
Post a Comment