Skip to content

Quarkus quick start, used for workshop with OpenShift DevSpace. Uses Quarkus and Postgres

Notifications You must be signed in to change notification settings

froberge/simple-quarkus-crud

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Getting started with Quarkus

This is a minimal CRUD service exposing a couple of endpoints over REST.

Under the hood, this demo uses:

  • RESTEasy to expose the REST endpoints
  • REST-assured and JUnit 5 for endpoint testing

Requirements

To compile and run this demo you will need:

  • JDK 1.11+
  • GraalVM

Configuring GraalVM and JDK 1.11+

Make sure that both the GRAALVM_HOME and JAVA_HOME environment variables have been set, and that a JDK 1.11+ java command is on the path.

See the Building a Native Executable guide for help setting up your environment.

Building the application

Launch the Maven build on the checked out sources of this demo:

./mvnw install

Live coding with Quarkus

The Maven Quarkus plugin provides a development mode that supports live coding. To try this out:

./mvnw quarkus:dev

This command will leave Quarkus running in the foreground listening on port 8080.

  1. Visit the default endpoint: http://127.0.0.1:8080.
  2. Visit the /hello endpoint: http://127.0.0.1:8080/hello
    • Update the response in src/main/java/com/thecat/quickstart/GreetingResource.java. Replace hello with hello there in the hello() method.
    • Refresh the browser. You should now see hello there.
    • Undo the change, so the method returns hello again.
    • Refresh the browser. You should now see hello.

Run Quarkus in JVM mode

When you're done iterating in developer mode, you can run the application as a conventional jar file.

First compile it:

./mvnw install

Then run it:

java -jar ./target/quarkus-app/quarkus-run.jar

Have a look at how fast it boots, or measure the total native memory consumption.

Run Quarkus as a native executable

You can also create a native executable from this application without making any source code changes. A native executable removes the dependency on the JVM: everything needed to run the application on the target platform is included in the executable, allowing the application to run with minimal resource overhead.

Compiling a native executable takes a bit longer, as GraalVM performs additional steps to remove unnecessary codepaths. Use the native profile to compile a native executable:

./mvnw install -Dnative

After getting a cup of coffee, you'll be able to run this executable directly:

./target/getting-started-1.0.0-SNAPSHOT-runner


Curl Example:

To delete a product

curl -X DELETE http://localhost:8080/products/{id}

To Add a Product

curl  --location --request POST 'http://localhost:8080/products/add' \
--header 'Content-Type: application/json' \
--data-raw \
'{"name": "Capuccino", "description": "DESC_CAPPUCCINO_01", "size": "SMALL" , "price": "4.25"}'

curl --location --request PUT 'http://localhost:8080/products/edit'
--header 'Content-Type: application/json'
--data-raw '{ "id": 1, "name": "Cortado", "description": "DESC_CORTADO_O1", "size": "SMALL" , "price": "7.25"}'

About

Quarkus quick start, used for workshop with OpenShift DevSpace. Uses Quarkus and Postgres

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published