无法获取id的数据

时间:2017-03-18 14:47:25

标签: mysql rest api metamug

我使用metamug构建我的REST API。我写了一个查询来获取学生的名字,提供了id。但是没有用。提供204状态代码作为回应。

<Request method="GET">
    <Desc> Get All Attendance </Desc>
    <Query>
        SELECT name from attendance 
        where id= $id 
    </Query>
</Request>

https://api.metamug.com/classroom/v1.0/attd?id=2

我的表查询如下

create table attendance (id int auto_increment primary key, name varchar(200))

感谢。

1 个答案:

答案 0 :(得分:2)

您几乎在$id特殊变量,在{{1} Item类型的请求中用作资源标识符 (有关Metamug / Collection请求的详细信息,请参阅Collection and Item RequestItem上的The Resource Identifier},此处您正在制作{Resource Identifier 1}}使用Collection时请求。您必须稍微修改资源文件

在Request标记中添加以下属性。

resource identifier

项目申请

item="true"

现在要传递<Request method="GET" item="true"> <Desc> Get All Attendance </Desc> <Query> SELECT name from attendance where id= $id </Query> </Request> 变量的值,您必须将其用作路径参数,而不是像查询字符串一样。

$id

该值将由https://api.metamug.com/classroom/v1.0/attd/{value that you've to pass}变量保存,所以在您的情况下,它将

https://api.metamug.com/classroom/v1.0/attd/2