#Same structure for get and post when use form with relations? What is the correct way

1 messages · Page 1 of 1 (latest)

tired pewter
#

I have this model (entity is a dropdown):
{
name:'a',
entity:{
id:1,
name:'Hp company'
}
}

For Get an Post always use this model..? Or two model like:

Get
{ name:'a', entity:{ id:1, name:'Hp company' } }

Post
{ name:'a', entityId:1 }

thorny tide
#

Requests and responses will often be very similar, but it is best to think of them as different entities. A rule of thumb for good API design is that it should:

  1. Only ask for what it needs
  2. Only return what was asked for

If you want to get clever, you might use TypeScript utility types like Pick, Omit, and Partial to reuse parts of interfaces.

tired pewter
#

yes I think so but for angular forms it's a bit roll