1

I am new to REST API currently i am working on a project where I have 2 resources:

  1. Project
  2. Client

Now for this did I need to create 2 resource class as given below or a single resource class.

@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) } 

Or a single resource class with all methods

@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 Answer 1

1

It's up to you, but taking SRP into consideration it's better to split the implementation into two classes. Remember that classes should be atomic and focus only on delivering single piece of functionality.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.