0

I am developing an application with Angular and Spring Boot. I have a model User which contains for example 10 fields. For a specific need, the frontend app needs just 3 or 4 fields(for example firstName, lastName, position and email).

In this case, what is the best method should I follow ? (Performances)

1- I create another class which contains 4 fields and use it to send the users list.

2- I send all users with 10 fields ?

If there is another way or method, please share it.

2 Answers 2

1

GrpahQL is a technology built to solve that problem. As a best practice is always good to send from the server only what you need.

Sign up to request clarification or add additional context in comments.

Comments

1

i had the same issue , what i have done is :

  • in the backend : sending an User object User in which i fill just the 4 fields which i need in the front (fill the other fields with a null value).
  • in the frontend : my User model contains just the 4 fields

  • after getting the object from the backend a simple assignment is sufficient to fill you object.

advantge : minimize the size of sent data via network.

Hope this helps :)

2 Comments

So you suggest to send all fields (4 with data and the other 6 fields with null). I think with this way, we don't minimize 100% nah ?
Yes not 100% but you minimize with a big pourcentage, this is a useful solution than creating another class then move from User to NewUser (with 4 fields..) .. , if you use my solution you can see the difference in your service rest's netwotk consomation..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.