Are we talking the request structure or response structure? Cause those are different things
Jul 19, 2022
4
Level 26
About API structure when having same fields
When designing an API how would you deal with same type fields. For example when you issue an invoice you need the issuer and the recipient (countrerpart). Let's assume we have API call to create an invoice, how is it better to structure the request?
Method 1:
{
"issuer_vat": "12345678",
"issuer_country": "GR",
"issuer_address": "Street 10",
"counterpart_vat": "87654321",
"countrerpart_country": "GR",
"counterpart_address": "Street 15"
}
Method 2:
{
"issuer": {
"vat": "12345678",
"country": "GR",
"address": "Street 10"
},
"counterpart": {
"vat": "87654321",
"country": "GR",
"address": "Street 15"
}
}
I prefer the first one since its simpler structure and easier to validate with backend (laravel).
Thank you.
Please or to participate in this conversation.