API: Is it correct to send back UI position related data in API response to the web/app clients?

时间:2017-04-10 03:27:57

标签: rest api api-design

I am developing a classified automobile valuation API that would return value of used cars.

Sample API request:

{
  "car": "BMW X3 sportline",
  "milesDriven": 20000,
  "yearOfPurchase": 2010,
  "askingPrice": "₹₹₹$20000"
}

The request sends car details with the price what seller expects.

Sample API response:

{
  "badConditionPrice": "₹₹₹$30000",
  "goodConditionPrice": "₹₹₹$35000"
}

The response sends back 2 prices to indicate rough estimate for ideal price the car should be sold at.

Now, at each client(web/app) we have to show all 3 prices - "askingPrice", "badConditionPrice", "goodConditionPrice".

While "badConditionPrice", "goodConditionPrice" has fixed position ["bad" at left and "good" at right], the position of "askingPrice" will vary. For example:

  1. If asking price is less than "badConditionPrice", it would be shown to left of "badConditionPrice" and "goodConditionPrice".
  2. If asking price is greater than "badConditionPrice" but less than "goodConditionPrice", it would be in middle.
  3. If asking price is greater than "goodConditionPrice" , it would be to the right of "goodConditionPrice".

My question is- who should decide the exact position of "askingPrice" - CLIENT or SERVER?

In case its server we need to send back flag to indicate its position OR if its client, we need to write this logic at each client.

1 个答案:

答案 0 :(得分:0)

这实际上取决于您如何定位数据和偏好。什么更容易,如果必须的话,你需要跳更少的地方以便以后改变?