2015-09-03 132 views
1

我新的REST API目前我工作的一個項目,我有2個資源:REST API設計與相關資源

  1. 項目
  2. 客戶

現在爲這個做了我需要創建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

這是給你的,但考慮SRP考慮它的更好的實施分爲兩個班。請記住,類應該是原子性的,並且只關注提供單個功能。