REST接口查找平均 [英] REST interface for finding average

查看:150
本文介绍了REST接口查找平均的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我想创建一个REST接口找到号码列表的平均值。假设数字都是一次提交的。你会怎样做呢?

Suppose I want to create a REST interface to find the average of a list of numbers. Assume that the numbers are submitted one at a time. How would you do this?


  1. 发表数 http://site.com/api/average

  2. 如果这是一个哈希将返回第一号

  3. 发表数 http://site.com/api/average/hash
    ....

  4. http://site.com/api/average/hash 求平均值

  5. 删除 http://site.com/api/average/hash 因为我们不需要它更多的

  1. POST a number to http://site.com/api/average
  2. If this is the first number a hash will be returned
  3. POST a number to http://site.com/api/average/hash ....
  4. GET http://site.com/api/average/hash to find the average
  5. DELETE http://site.com/api/average/hash since we dont need it any more

这是做的正确方法?有什么建议么?

Is this the right way to do it? Any suggestions?

推荐答案

这更有意义,认为数字作为资源的名单。假设每个列表的资源URL是 /列表/ {ID} ,其中 {ID} 是列表的ID的占位符。然后:

It makes more sense to think of the list of numbers as the resource. Suppose each list's resource URL is /list/{id} where {id} is a placeholder for the list's ID. Then:


  1. POST /列表创建一个新的列表,服务器生成一个列表ID(或哈希),并指定了 /列表/ {ID } URL在响应中的位置头。

  2. POST /列表/ {ID} 添加一个数字列表

  3. GET /列表/(编号)/平均返回平均值

  4. 删除/列出/ {ID} 删除列表。

  1. POST /list creates a new list, the server generates a list ID (or 'hash') and specifies the /list/{id} URL in the response's Location header.
  2. POST /list/{id} adds a number to the list
  3. GET /list/{id}/average returns the average
  4. DELETE /list/{id} deletes the list.

GET /列表的替代/(编号)/平均将是 GET /列表/ {ID} 返回列表作为结构化数据,如XML,其中包括的平均值作为一个生成的属性

An alternative to GET /list/{id}/average would be for GET /list/{id} to return the list as structured data, e.g. XML, that includes the average as a generated property.

这篇关于REST接口查找平均的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆