Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dropwizard - organizing your project, understanding terminology, etc

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!

like image 886
Sun Avatar asked Apr 12 '13 17:04

Sun


People also ask

What is Dropwizard framework?

What is Dropwizard? Dropwizard is an open source Java framework for developing ops-friendly, high-performance RESTful backends. It was developed by Yammer to power their JVM based backend. Dropwizard provides best-of-breed Java libraries into one embedded application package.

What is managed in Dropwizard?

Dropwizard provides the Managed interface for this. You can either have the class in question implement the #start() and/or #stop() methods, or write a wrapper class which does so. Adding a Managed instance to your application's Environment ties that object's lifecycle to that of the application's HTTP server.

How do I add resources to Dropwizard?

Registering A Resource A Dropwizard application can contain many resource classes, each corresponding to its own URI pattern. Just add another @Path -annotated resource class and call register with an instance of the new class. Before we go too far, we should add a health check for our application.


2 Answers

  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.

like image 75
Sandy T Avatar answered Oct 28 '22 18:10

Sandy T


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.

like image 41
DarkKnight Avatar answered Oct 28 '22 18:10

DarkKnight