关于RESTful设计的一个疑问

WBOY
Release: 2016-06-06 20:41:19
Original
964 people have browsed it

最近在写aws相关的开发,有这样一个问题:比如关于instance的操作有创建、重启、停止、删除等,如果按照RESTful设计风格应该如何实现?

<code>GET     /etc/instance/    获取instance
POST    /ec2/instance/    创建instance
DELETE  /etc/instance/    删除instance
</code>
Copy after login
Copy after login

那重启、停止等操作呢?用PUT?

回复内容:

最近在写aws相关的开发,有这样一个问题:比如关于instance的操作有创建、重启、停止、删除等,如果按照RESTful设计风格应该如何实现?

<code>GET     /etc/instance/    获取instance
POST    /ec2/instance/    创建instance
DELETE  /etc/instance/    删除instance
</code>
Copy after login
Copy after login

那重启、停止等操作呢?用PUT?

恰好在做一个管理服务的 RESTSful api 设计,说一下我的设计思路供参考。

<code># 创建
POST /ec2/instance

# 查询状态
GET /ec2/instance/:id

# 删除(terminate)
DELETE /ec2/instance/:id

# 启动、重启等都算作修改状态,假定是在修改 instance 的 status 属性

# 启动
PUT /ec2/instance/:id
Form data: status=start

# 停止
PUT /ec2/instance/:id
Form data: status=stop

# 启动,如果已启动就重启
PUT /ec2/instance/:id?force=1
Form data: status=start
</code>
Copy after login

关于RESTful设计的一个疑问

用一个rails的url设计来回答,手懒了

RESTful是啥?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template