Generate a http4s project wired with Grafter. Use the following command:
sbt new jcranky/grafter-http4s.g8 -b 0.19
then just enter the values you will be prompted for, cd
to the folder
generated for your project, and run
:
cd [your-project-name]
sbt run
The run
command will require you to choose what you want to run: Application
or Visualize
. The first one runs the http4s server, and the second one generates
the application component graph (see Visualize.scala
for more information).
You can find more information about Grafter itself here: https://github.com/zalando/grafter
The application generated by this template is very opinionated, but it is just a suggestion on how to use Grafter. The sections below explain the application is organized.
As briefly mentioned above, there are two runnable components: Application
and
Visualize
. Application
is the main entry point of the project itself: it loads
all the application components and starts the http4s server - as long as everything
is ok.
Visualize
loads the same application components but, instead of starting a server,
it uses Grafter to generate the application components graph using dot notation.
See the Visualize.scala
file and Grafter's documentation for more details.
This is the root object of the application, where the whole application graph is built from. We use this, as mentioned in the previous section, both to start the application itself and to generate the visualization of the application graph.
Http4s entrypoint in the application, where the Rest endpoints are defined and exposed.
All rest endpoints are defined in the routes
package. A class named RestApi
is used to collect all the application's endpoints together, so that they can
easily be used from the HttpServer
.
Basically a services layer. Nothing special is happening here, but objects in this
layer depends on the repository
layer.
Data access layer.