Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

isarantoglou's avatar

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.

0 likes
4 replies
Sinnbeck's avatar

Are we talking the request structure or response structure? Cause those are different things

Sinnbeck's avatar

@isarantoglou then I would go with 1. And 2 for response :)

1 is easier to work with for both you and your end user and it's a common setup for apis

1 like
martinbean's avatar

@isarantoglou If you want to follow RESTful best practices, then you should be sending data in the same way it’s returned. It’s confusing to the end user that you have multiple representations for the same entity.

“Oh, if you’re sending stuff, send it in this format. But when we send you the same thing back, it’ll look like this instead.”

1 like

Please or to participate in this conversation.