I have a class Person.
Person {
String firstName;
String lastName;
String Date dob;
String email;
String mobileNumber;
String address;
}
To add a person, I have following REST APIs:
POST /person
{ "firstName":"Donald", "lastName":"Trump", "dob":"01/01/1990" }
PUT /person/{id}/addContact
{ "email":"[email protected]", "mobileNumber":"+1-123-456-789" }
PUT /person/{id}/addAddress
{ "address":"white house" }
Now there are two ways to do that -
Use same Person class and keep adding new information in the same object from API 1, 2 and 3.
Create separate models for all three APIs.
PersonMain { String firstName; String lastName; String Date dob; } PersonContact { String email; String mobileNumber; } PersonAddress { String address; }
Finally, we also need our main Person class because all that information is going into single Person table and finally this whole Person object will be used at every place.
What do you think which approach is good and why?
PUT /person/{id}/addAddress
on an existing Person object the only way to set the address, or can it also be set as part of a complete Person object withPOST /person/
orPUT /person/{id}
?