The server is implemented using Spring Boot.
The server exposes three public JSON API data endpoints:
- /api/heros - returns an array containing lightweight representation of heros
- /api/hero/:id - returns an object containing all fields for a specific hero specified by id
- /api/hero/name - returns an object containing all fields for a specific hero specified by name
Port 8090 is set in application.properties for developing locally and this is used by unit tests too.
All files for Hero web micro-service is located in package com.example.demo.heroes. All reusable base classes and utilites needed are located in com.example.demo.core.
The provided data source file dc_heroes.csv is located in src/main/resource and its content of DC comics hero information is copied from their repo here.
Each line is parsed and each hero data is fed into a Hero class object by heroes/HerosCSVFileImported and the objects are saved into memory-persistence using H2 by the hero/HeroRepositoryHandler. The Hero class (entity) itself stores short information (name, alter ego and id) as attributes from a hashmap argument and the leftovers are kept in a details map. In order to provide short information, typically when listing all heroes, a get method Hero.getShortInfo() is used.
The CRUD repository has been chosen for implementation by heroes/HeroRepository. The actual service hero/HeroService is separated from the REST controller hero/HeroController. Tests are available in the normal test folder.
Java 8 JDK Install JDK
Gradle 4.8.1 Install Gradle
Spring Boot 2.04 Install Spring boot CLI
The project is preferrably imported using the free IDE IntelliJ IDEA community edition (recommended).
- Select import project
- Check Run | Edit Configurations and Run/Debug Configurations and if empty, click "+"-button and select Application.
- Ensure configuring the project as the following:
- Name: Heros
- Main.class: com.example.demo.Application
- Class.path: demo_main
- JRE: 1.8
- Now build from Build | Build Project.
- If all goes well, hit Run | Run 'Heros'. The Spring logo should be seen in the Run window.
You may also build and run from a CLI: ./gradlew bootRun`