当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Webservice API design: return type for display or type code only or both?

问题描述:

Web service design - how should my web service response?

Example a Phone number can have type "Home telephone", "Business telephone", "Customer Service telephone" etc

Should my web service API return in the response with "PhoneTypeCode" or PhoneTypeName (used for display)?

Example of Business telephone type

1) PhoneTypeCode: "business"

2) PhoneType: "Business telephone"

3) Return both?

网友答案:

Depending on your needs either approach is fine.

When deciding consider:

  • if client have special hadnling for different types - in this case code would be easier to handle.
  • if there are localization concerns and if your service already provides localized responses (i.e. you return numbers/dates as localized strings, or you require culture to be passed in request and other strings are localized accordingly). If your server does not provide any locaization support - returing strings could be confsing.
  • if set of types is complete - if not retyring type as string (non-localized) may be better as it forces client to start handling "unknown" types earlier.
分享给朋友:
您可能感兴趣的文章:
随机阅读: