RESTful API设计规范

HTTP方法

URI

方法

参数

示例

备注

GET

/resource

index

@RequestMapping()

@ResponseBody

Public Result index(Domain condition)

显示所有资源

GET

/resource/1

show

Id=1

@RequestMapping(path=”{id}”)

@ResponseBody

public Result show(@PathVariable Long id)

显示单个资源

GET

/resource/1/edit

edit

Id=1

@RequestMapping(path=”{id}/edit”)

@ResponseBody

public Domain edit(@PathVariable Long id);

编辑单个资源

GET

/resource/new

editNew

@RequestMapping(path=”new”);

public String editNew();

新建

POST

/resource

create

@RequestMapping(method=RequestMethod.POST);

@ResponseBody

public Result create(Domain domain);

创建单个资源

PUT

/resource/1

update

Id=1

@RequestMapping(path=”{id}”,method=RequestMethod.UPDATE);

@ResponseBody

public Result update(@PathVariable Long id);

更新单个资源

DELETE

/resource/1

destroy

Id=1

@RequestMapping(path=”{id}”,method=RequestMethod.DELETE);

@ResponseBody

public Result destroy(@PathVariable Long id);

删除单个资源

POST

/resource/batch/create

batchCreate

@RequestMapping(path=”batch/create”,method=RequestMethod.POST);

@ResponseBody

public Result batchCreate(List<Domain> domains);

创建多个资源

POST

/resource/batch/update

batchUpdate

@RequestMapping(path=”batch/update”,method=RequestMethod.POST);

public Result

@ResponseBody

batchUpdate(List<Domain> domains);

更新多个资源

POST

/resource/batch/destroy

batchDestroy

@RequestMapping(path=”batch/destroy”,method=RequestMethod.POST);

@ResponseBody

public Result batchDestroy(List<Domain> domains);

删除多个资源

POST/GET

/resource/action

action

@RequestMapping(path=”action”);

@ResponseBody

public Result action(参数);

对资源的其他操作

说明:

1.resource代表对服务器请求的资源,比如进件,客户资料,发标信息等等

2.action代表除crud外的操作,命名尽量见文知意

3.标蓝色的对于SPA来说可能不需要,如果是传统的web页面则需要

4.参数只列出了url中的,表单中的未在上表格中体现

5.Domain泛指各种实体,写具体接口要以具体实体类替换

6.Result有两种含义,一种是泛指返回的结果类型,可以是各种实体或实体集合等等,另外一种是指结果的封装,即Result中封装Message对象与实体对象,Message对象提供处理结果与消息,实体对象作为展示数据,这里推荐第二种方式

有好的意见,请大家提出来,谢谢。

相关文章

迭代器模式(Iterator)迭代器模式(Iterator)[Cursor]意图...
高性能IO模型浅析服务器端编程经常需要构造高性能的IO模型,...
策略模式(Strategy)策略模式(Strategy)[Policy]意图:定...
访问者模式(Visitor)访问者模式(Visitor)意图:表示一个...
命令模式(Command)命令模式(Command)[Action/Transactio...
生成器模式(Builder)生成器模式(Builder)意图:将一个对...