Need Suggestion :
I am writing a generic API which needs to return attributes of a Customer. And, Customer can be of many different types like Retail Customer, Merchant Customer etc. Input to the API is customer id.
What is the better approach to form a API response structure in this scenario - Option 1) Response should have Map of key-value pair for the resource attributes, Option 2) Response to have object where attribute names are clearly defined as field names.
Few pros/cons of both approach which comes to my mind -
Option 1- gives more flexibility from future perspective as we don't need to change the API response structure if a new attribute is added to a resource. Also, using this I can handle response of different customer types.
Option 2- looks better from consumer perspective. This gives more clarity in terms of response structure, as API will have clear defined properties. The disadvantage on the other hand would be extra nullable fields being returned when the property is not relevant to a particular type of customer.
Please advise ?
Aucun commentaire:
Enregistrer un commentaire