[英]Rest Api Design with dependent resources
我是REST API的新手,目前正在从事一个拥有2个资源的项目:
现在,我需要创建以下两个资源类或一个资源类。
@Path("/v1/projects")
public interface ProjectResource {
@POST
public Respone add(Project project)
@DELETE
public Respone delete(Project project)
@PUT
public Respone update(Project project)
}
@Path("/v1/projects/{projectId}/client")
public interface ClientResource {
@POST
public Respone add(Client client)
@DELETE
public Respone delete(Client client)
@PUT
public Respone update(Client client)
}
或具有所有方法的单个资源类
@Path("/v1/projects")
public interface ProjectResource {
@POST
public Respone add(Project project)
@DELETE
public Respone delete(Project project)
@PUT
public Respone update(Project project)
@Path("/{projectId}/client")
@POST
public Respone add(Client client)
@Path("/{projectId}/client")
@DELETE
public Respone delete(Client client)
@Path("/{projectId}/client")
@PUT
public Respone update(Client client)
}
这取决于您,但是考虑到SRP ,最好将实现分为两类。 请记住,类应该是原子性的,并且只专注于交付单个功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.