简体   繁体   English

客户端的 REST API 响应建模 - 最佳实践

[英]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将 JSON 转换为包含所有数据/属性的类对象并在我的代码中使用此类对象
  • convertting JSON to class object which contains only those data/properties which are needed for futher processing将 JSON 转换为仅包含进一步处理所需的数据/属性的类对象
  • 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将 JSON 转换为仅包含进一步处理所需的数据/属性的类对象

It does not make sense to use data which is not needed.使用不需要的数据是没有意义的。 It makes only confusion.它只会造成混乱。 I would rather use multiple classes.我宁愿使用多个类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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