简体   繁体   English

为两点之间的路径设计WebService API

[英]Designing of a WebService API for paths between two points

I have a Web Service which returns details of path between given two input points if exists. 我有一个Web服务,如果存在,它将返回给定两个输入点之间的路径的详细信息。 The Web Service API is something like getPath(Point start,Point end). Web服务API类似于getPath(Point start,Point end)。 Now if the path doesn't exist between given start & end points, how should API behave among below options 现在,如果在给定的起点和终点之间不存在路径,则以下选项之间的API行为应如何

  1. Return a null object 返回一个空对象
  2. Throw a PathNotFoundException 抛出PathNotFoundException
  3. Always include a status code in the response along with path details. 始终在响应中包括状态代码以及路径详细信息。 In this case return empty path and status code as appropriate error code like "PATH_NOT_FOUND" / "ERROR" 在这种情况下,请返回空的路径和状态代码作为相应的错误代码,例如“ PATH_NOT_FOUND” /“ ERROR”
  4. Any other option? 还有其他选择吗? Please suggest. 请提出建议。

Please let me know your views 请让我知道您的意见

Thanks, Harish 谢谢,哈里斯

Suggestion: 1. return null or empty path. 建议:1.返回null或空路径。

Throwing exceptions across http is probably not the best idea and returning status codes is a way to workaround throwing exceptions. 在http上引发异常可能不是最好的主意,并且返回状态代码是解决异常的一种方法。 The lack of a path is not something that should occur as error at the client side. 缺少路径不应在客户端作为错误发生。

I would reserve exceptions/status codes for wrong parameters, wrong number of parameters, some server-side problems like inaccessible database etc. 我会为错误的参数,错误的参数数量,一些服务器端问题(如无法访问的数据库)保留异常/状态代码。

Suppose you are querying the database for a list of customers from NY. 假设您要在数据库中查询来自纽约的客户列表。 Would you throw an exception if the list is empty or just return an empty list? 如果列表为空或仅返回一个空列表,是否会引发异常? This sounds exactly like your scenario. 这听起来很像您的情况。

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

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