docs
reference
tessl install tessl/maven-io-quarkus--quarkus-rest@3.15.0A Jakarta REST implementation utilizing build time processing and Vert.x for high-performance REST endpoints with reactive programming support, security integration, and cloud-native features.
This guide will help you create your first Quarkus REST application.
mvn io.quarkus:quarkus-maven-plugin:3.15.7:create \
-DprojectGroupId=com.example \
-DprojectArtifactId=rest-quickstart \
-Dextensions="quarkus-rest,quarkus-rest-jackson"
cd rest-quickstartmvn io.quarkus:quarkus-maven-plugin:3.15.7:create \
-DprojectGroupId=com.example \
-DprojectArtifactId=rest-quickstart \
-Dextensions="quarkus-rest,quarkus-rest-jackson" \
-DbuildTool=gradle
cd rest-quickstartCreate src/main/java/com/example/GreetingResource.java:
package com.example;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
@Path("/hello")
public class GreetingResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "Hello from Quarkus REST!";
}
}./mvnw quarkus:devOr with Gradle:
./gradlew quarkusDevcurl http://localhost:8080/helloOutput: Hello from Quarkus REST!
Update GreetingResource.java:
import jakarta.ws.rs.PathParam;
@Path("/hello")
public class GreetingResource {
@GET
@Path("/{name}")
@Produces(MediaType.TEXT_PLAIN)
public String hello(@PathParam("name") String name) {
return "Hello " + name + "!";
}
}Test:
curl http://localhost:8080/hello/AliceOutput: Hello Alice!
Create src/main/java/com/example/Greeting.java:
package com.example;
public class Greeting {
public String message;
public long timestamp;
public Greeting(String message) {
this.message = message;
this.timestamp = System.currentTimeMillis();
}
}Update GreetingResource.java:
import jakarta.ws.rs.core.MediaType;
@Path("/hello")
public class GreetingResource {
@GET
@Path("/{name}")
@Produces(MediaType.APPLICATION_JSON)
public Greeting hello(@PathParam("name") String name) {
return new Greeting("Hello " + name + "!");
}
}Test:
curl http://localhost:8080/hello/AliceOutput: {"message":"Hello Alice!","timestamp":1706000000000}
Add to GreetingResource.java:
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Consumes;
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Greeting create(Greeting greeting) {
greeting.timestamp = System.currentTimeMillis();
return greeting;
}Test:
curl -X POST http://localhost:8080/hello \
-H "Content-Type: application/json" \
-d '{"message":"Custom message"}'import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.DefaultValue;
@GET
@Produces(MediaType.APPLICATION_JSON)
public Greeting greet(
@QueryParam("name") @DefaultValue("World") String name,
@QueryParam("formal") @DefaultValue("false") boolean formal) {
String message = formal
? "Good day, " + name
: "Hello " + name + "!";
return new Greeting(message);
}Test:
curl "http://localhost:8080/hello?name=Alice&formal=true"./mvnw package
java -jar target/quarkus-app/quarkus-run.jar./mvnw package -Dnative
./target/rest-quickstart-1.0.0-SNAPSHOT-runner