This is my implementation of a Product REST resource / endpoint / service
using the latest cloud-native development Java framework - Quarkus
Before starting the application itself, you must run the database first.
The database is going to be executed as a docker container from the latest Postgres image.
Execute the following command to run this database container:
docker run --name products_pgcontainer -e POSTGRES_PASSWORD=secret123 -d -p 5432:5432 -v products_pgdata:/var/lib/postgresql/data postgres
Now you need to clone this repo to run the application.
After cloning, open the project in your IDE by clicking on the pom.xml file.
Then you can run the application using one of the following two ways:
You can run (and re-run) the application in dev mode, which enables live coding using the following command:
./mvnw clean compile quarkus:dev
For this method, you need to follow these steps:
- Replace localhost with host.docker.internal in application.properties file
under the src/main/resources directory. - Package this application using the following command:
- Build the docker image of this application using the following command:
- Run a container from this image using the following command:
./mvnw clean package
docker build -f src/main/docker/Dockerfile.jvm -t ProductResource-REST-Quarkus-jvm .
Note: This step and the two previous ones are performed only once.
docker run -i --rm -p 8080:8080 ProductResource-REST-Quarkus-jvm
Note: This command is needed every time you want to execute the application as a docker container, because the container is automatically removed when stopped.
Finally, you can start using the API endpoints of the application!! 🥳🎉
To know all the endpoints available and start trying them out, click the following link:
Note: When using the POST and PUT endpoints, take care not to set the value of ID field as it's automatically generated.