使用依赖资源休息Api设计

时间:2015-09-03 06:21:56

标签: rest

我是REST API的新手,目前我正在开发一个项目,我有2个资源:

  1. 项目
  2. 客户端
  3. 现在,我需要创建下面给出的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)
    
    }
    

1 个答案:

答案 0 :(得分:1)

由您决定,但考虑到SRP,最好将实施分为两类。请记住,类应该是原子的,并且只关注提供单一功能。