Git Product home page Git Product logo

book-catalog's Introduction

book-catalog

This is a basic example application written with Micronaut that publishes a catalog of books from a MongoDB database via an HTTP API and a server-side Handlebars view.

The example also includes Lombok integration, Jackson configuration, reactive MongoDB connectivity, ConfigurationProperties and a test environment stub.

Please note that additional security configuration is required to use the project in production.

Requirements

How to run the service?

Start the service by executing the bash-script run.sh.

This will:

  • build the Micronaut application JAR file (using the Gradle wrapper),
  • run a Docker multi-container application in daemon mode (using docker-compose),
    • with a MongoDB container
    • with a Micronaut application container
  • seed the MongoDB database with some books (using docker-compose and mongoimport).

You should be able to access http://localhost:8080/ and http://localhost:8080/api/books within a few seconds after the Docker containers are started.

If you are using Docker machine the host might be different (e.g. 192.168.99.100).

Port 8080 of the Micronaut container is exposed to port 8080 by default. You can change the local port by defining the environment variable APPLICATION_PORT:

APPLICATION_PORT=8888 ./run.sh

You can track the logfiles via docker-compose logs -f.

How to stop the service?

Stop the service by executing the bash-script clean.sh.

This will:

  • remove the "build/" directory (from the Gradle build),
  • stop (or kill after 10sec) the Docker multi-container application (using docker-compose),
  • remove all attached Docker resources,
  • remove the Micronaut application image.

How was the project created?

The project itself, the Java beans and controller skeletons were scaffolded using the Micronaut CLI:

$ mn create-app catalogservice.book-catalog --features mongo-reactive
| Generating Java project...
| Application created at /Volumes/projects/github.com/JonasHavers/book-catalog
$ cd book-catalog/
$ mn
| Starting interactive mode...
| Enter a command name to run. Use TAB for completion:
mn> create-bean catalogservice.application.FindBooksUseCase
| Rendered template Bean.java to destination src/main/java/catalogservice/application/FindBooksUseCase.java
mn> create-bean catalogservice.adapter.mongodb.MongoBooksRepository
| Rendered template Bean.java to destination src/main/java/catalogservice/adapter/mongodb/MongoBooksRepository.java
mn> create-controller catalogservice.adapter.web.BooksApiController
| Rendered template Controller.java to destination src/main/java/catalogservice/adapter/web/BooksApiController.java
| Rendered template ControllerTest.java to destination src/test/java/catalogservice/adapter/web/BooksApiControllerTest.java
mn> create-bean catalogservice.adapter.test.StubBooksRepository
| Rendered template Bean.java to destination src/main/java/catalogservice/adapter/test/StubBooksRepository.java

The Lombok dependency and annotation processor were added to the project in build.gradle right before Micronaut's annotation processors:

compileOnly "org.projectlombok:lombok:1.18.4"             // added
annotationProcessor "org.projectlombok:lombok:1.18.4"     // added
annotationProcessor "io.micronaut:micronaut-inject-java"

The Handlebars dependency was added to the project in build.gradle to support server-side view rendering:

runtime "com.github.jknack:handlebars:4.1.2"

The controller that is responsible for the routing and the view model creation was also scaffolded:

$ mn create-controller catalogservice.adapter.web.BooksViewController
| Rendered template Controller.java to destination src/main/java/catalogservice/adapter/web/BooksViewController.java
| Rendered template ControllerTest.java to destination src/test/java/catalogservice/adapter/web/BooksViewControllerTest.java

Implementation and configuration followed the scaffolding. For further details, please refer to the Git history.

Author

Jonas Havers (@JonasHavers) - https://jonas-havers.de

book-catalog's People

Contributors

jonashavers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.