1

注意:我不是在寻找域可用性网络服务!既然我们已经解决了这个问题......

我将如何构建一个系统,既允许我们通过我们的 REST API 从我们的域组合中检索资源,又在同一个 API 中执行域可用性检查?对这两种情况使用相同的 URI 是个好主意,还是应该为此使用不同的资源?

例如:

如果我想要关于 example.com 的信息(这是我们投资组合中的一个域),我会GET /domains/example.com/检索我们的信息(注册信息,如域名服务器、联系人等……还有内部信息,如我们的客户记录、发票号码等...)。

如果我想获得 example.org 的域可用性(它没有在我们这里注册,所以不在我们的投资组合中),我也会调用GET /domains/example.org/which 然后返回域是否可用。

简而言之:对这两件事使用相同的 URI 是个好主意(基本上都返回域上的信息?)还是我应该为此使用不同的资源?/domainregistration/example.com/例如?

4

1 回答 1

1

The basic idea of a REST API is to provide an abstraction of implementation details and logic of, in your case, domain information. Under this point of view the abstraction could fit because you retrieve domain information from domains in your portfolio and from domains not in your portfolio.

But there is also some difference in retrieving domain information, for example retrieving domain information about domains not in your portfolio is slow, or at least slower than retrieving information for domains in your portfolio. Another difference is that for REST APIs often some bulk capabilities for retrieving more than one resource information are provided like this GET /domains/example.com,anotherexample.com,localhost.com/. You will/might not want such functionality to be accessible when retrieving information about domains that are not in your portfolio.

Another reason why you might split the resources is that you could implement a call that retrieves all information about domains in your portfolio:

GET /domains/

This request could obviously only return information about domains in your portfolio, so your abstraction would break in that case.

When you model your REST API to retrieve domain availability I would suggest to use a resource like

PUT /availabilities/example.com

to create a domain availability check. This resource could create a sub resource example.com that can be then used to retrieve information about this availability check, or used to cache domain availability check results via:

GET /availabilities/example.com

Taking all these arguments together I'd favor splitting resources, because:

  • In case an API user is interested in detailed domain information of domains in your portfolio the API user could check the /domains resource
  • To get information if a domain is in your portfolio the user would also use the /domains/example.com resource
  • API users that are only interested in a domain availability check can use the availabilities resource to perform this check.
于 2013-02-20T15:53:11.753 回答