RESTful API设计规范

 

HTTP方法web

URI服务器

方法名app

参数dom

示例url

备注对象

GET接口

/resource资源

indexit

 

@RequestMapping()io

@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对象提供处理结果与消息,实体对象做为展现数据,这里推荐第二种方式

有好的意见,请你们提出来,谢谢。

相关文章
相关标签/搜索