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:
Please explain, in general terms, the difference between 'api', 'service' and 'client'.
Is there an example which strictly follows the above convention using dropwizard?
"...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!
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.
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.
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.
Dropwizard recommends that you follow the below project structure:
{project_name} (i.e parent with following modules)
You may find this example helpful, even though client part is empty.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With