Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/dario-vega/test-helidon


https://github.com/dario-vega/test-helidon

Last synced: 1 day ago
JSON representation

Awesome Lists containing this project

README

        

= helidon
:toc: auto

Sample Helidon MP project that includes multiple REST operations.

== Build and run

With JDK21
[source,bash]
----
mvn package
java -jar target/helidon.jar
----

== Exercise the application

Basic:
[source,bash]
----
curl -X GET http://localhost:8181/simple-greet
Hello World!
----

JSON:
[source,bash]
----
curl -X GET http://localhost:8181/greet
{"message":"Hello World!"}

curl -X GET http://localhost:8181/greet/Joe
{"message":"Hello Joe!"}

curl -X PUT -H "Content-Type: application/json" -d '{"greeting" : "Hola"}' http://localhost:8181/greet/greeting

curl -X GET http://localhost:8181/greet/Jose
{"message":"Hola Jose!"}
----

== Try metrics

[source,bash]
----
# Prometheus Format
curl -s -X GET http://localhost:8181/metrics
# TYPE base:gc_g1_young_generation_count gauge
. . .

# JSON Format
curl -H 'Accept: application/json' -X GET http://localhost:8181/metrics
{"base":...
. . .
----

== Interacting with the API

To interact with the API provided by the `BeerResource` class using `curl`, you can use the following commands:

* **Get all beers**:
[source,bash]
----
curl -X GET http://localhost:8181/beers
----

* **Get a specific beer by ID**:
[source,bash]
----
curl -X GET http://localhost:8181/beers/
----
Replace `` with the actual ID of the beer you want to retrieve.

* **Insert a new beer**:

[source,bash]
----
curl --location --request PUT 'http://localhost:8181/beers' \
--header 'Content-Type: application/json' \
--data '{"style":"IPA", "hop":"Cascade", "malt":"Pale Ale", "comments":["Great beer!", "Highly recommended."]}'
----

* **Delete a beer by ID**:
[source,bash]
----
curl -X DELETE http://localhost:8181/beers/
----

Replace `` with the actual ID of the beer you want to delete.

== Try health

[source,bash]
----
curl -s -X GET http://localhost:8181/health
{"outcome":"UP",...
----

== Building a Native Image

The generation of native binaries requires an installation of GraalVM 22.1.0+.

You can build a native binary using Maven as follows:

[source,bash]
----
mvn -Pnative-image install -DskipTests
----

The generation of the executable binary may take a few minutes to complete depending on your hardware and operating system. When completed, the executable file will be available under the `target` directory and be named after the artifact ID you have chosen during the project generation phase.

== Building the Docker Image

[source,bash]
----
docker build -t helidon .
----

== Running the Docker Image

[source,bash]
----
docker run --rm -p 8181:8181 helidon:latest
----

Exercise the application as described above.

== Run the application in Kubernetes

If you don’t have access to a Kubernetes cluster, you can link:https://helidon.io/docs/latest/#/about/kubernetes[install one] on your desktop.

=== Verify connectivity to cluster

[source,bash]
----
kubectl cluster-info // Verify which cluster
kubectl get pods // Verify connectivity to cluster
----

=== Deploy the application to Kubernetes

[source,bash]
----
kubectl create -f app.yaml // Deploy application
kubectl get pods // Wait for quickstart pod to be RUNNING
kubectl get service helidon // Get service info
----

Note the PORTs. You can now exercise the application as you did before but use the second port number (the NodePort) instead of 8181.

After you’re done, cleanup.

[source,bash]
----
kubectl delete -f app.yaml
----

== Building a Custom Runtime Image