18

I am learning to use Dropwizard. I was able to follow the quickstart guide and run basic REST APIs.

In this documentation, there is a section called "Organizing your project".

It recommends to organize your project in following parts: project-api, project-client, project-service.

Here are my questions/queries:

  1. Please explain, in general terms, the difference between 'api', 'service' and 'client'.

  2. Is there an example which strictly follows the above convention using dropwizard?

  3. "...project-client should use those classes and an HTTP client to implement a full-fledged client for your service" --- since 'project-service' will have the REST APIs, then why do we need to use HTTP Client?

Thanks!

Martin Konecny
  • 57,827
  • 19
  • 139
  • 159
Sun
  • 559
  • 2
  • 9
  • 30

2 Answers2

21
  1. Dropwizard recommends that you follow the below project structure:

    {project_name} (i.e parent with following modules)

    • {project_name}-api : should have all the value objects/POJO's that you are using in your project.
    • {project_name}-client : should contain client code used to get data from external rest service. Can be excluded, if you don't have any.
    • {project_name}-service : contains the remaining (service, configuration , resources, dao...etc).
  2. You may find this example helpful, even though client part is empty.

  3. As mentioned in the short description for client in point 1, if your project has any call to external rest services then related (HTTP)client code should go inside client module. Otherwise exclude the module itself.

Sandy T
  • 390
  • 3
  • 8
11

1) api - as by the name, it is the interface/contract which defines as Representations(Pojo -Json/Xml) in the project. These model define your API contracts, which could be shared with different project who are consuming your API.

2) service - actual business logic and persistence. Representations needn't be same as your Entity objects (domain objects). This splits your domain and representations in a more clear way. Domain logic will no longer couple to your representation. Although this can cause significant duplication in terms of object structure.

Project Dependency - depends on "api", "client"

3) client- An Http Client wrapper to call other web services through HTTP calls using HttpClient or Jersey Client. Write (end-user) based testing for the contracts.

Project Dependency - depends on "api"

Hope this helps.

DarkKnight
  • 766
  • 1
  • 8
  • 20