简体   繁体   中英

REST API response modelling on client side - best practices

My application is integrated with some external service and makes requests to that service for data. I am just wondering what is the best practice for modelling the responses on the client side, especially in case when client business logic require only some peace of data. I am considering following implementations:

  • converting JSON to class object which contains all data/properties and use such object in my code
  • convertting JSON to class object which contains only those data/properties which are needed for futher processing
  • combination of both above (creating class object containing all properties and than converting it to object containing only properties required for further business logic)

I would do the second.

converting JSON to class object which contains only those data/properties which are needed for further processing

It does not make sense to use data which is not needed. It makes only confusion. I would rather use multiple classes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM